How to send email from app ?

How to send email from app ?

Postby HunterEC » Sun Mar 06, 2011 10:11 am

Guys:

How can I send / receive email from within a FiveWin app ? Thank you.
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Re: How to send email from app ?

Postby Jack » Sun Mar 06, 2011 11:09 am

Here is some code from Fivewin :
*
aaqui:={}
winfo:="Content of the message)
wsubject:="Subject of the message"
aadd(aaqui,"test@test.be")

oOutM1 := TSmtp():New( cIP := GetHostByName( "smtp.ulg.ac.be" ) )
*
oMail := TSmtp():New( cIP := GetHostByName( "smtp.ulg.ac.be" ) )
*
oMail:bConnecting = { || oWnd:SetMsg( "Connecting to smtp ..." ) }
oMail:bConnected = { || oWnd:SetMsg( "Connected" ) }
*
oMail:bDone = { || oWnd:SetMsg( "Mail Done" ) }
*
oMail:SendMail("jclip@skynet.be" ,; // From
aaqui,; // To
wdetail ,; // Msg Text
wsubject,; // Subject
{} ) // Attached files
*
Jack
 
Posts: 288
Joined: Wed Jul 11, 2007 11:06 am

Re: How to send email from app ?

Postby Jack » Sun Mar 06, 2011 11:12 am

Here is a sample with Outlook

oOutLook := TOleAuto():New("Outlook.Application")
*
oMailItem := oOutLook:Invoke("CreateItem", 0)
oMailitem:to:="slfpvsoa@skynet.be" && si plusieur separe ;
oMailitem:CC:="ph.jacquet@skynet.be;test@test.be"
oMailItem:Set("Subject","Mail membres (Complet)")
oMailItem:Set("Body","Membres complet")
oMailItem:Attachments:Add("i:\slfp\expall.dbf")
oMailItem:display(.F.)
**
Jack
 
Posts: 288
Joined: Wed Jul 11, 2007 11:06 am

Re: How to send email from app ?

Postby Jack » Sun Mar 06, 2011 11:17 am

Here is a sample with GMAIL :

* ===
function VAMAIL(p1)
Local oEmailCfg,oEmailMsg,oError,cHtml,lef
*
lef:=fcreate("n:\tables\bio_tx\info.txt")
fwrite(lef,"Start log"+CRLF)
fwrite(lef,p1+CRLF)
fclose(lef)
*
cHtml:='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">'
cHtml+='<HTML><HEAD>'
cHtml+='<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>'
cHtml+='<META name=GENERATOR content="MSHTML 8.00.6001.18783">'
cHtml+='<STYLE></STYLE>'
cHtml+='</HEAD>'
cHtml+='<BODY bgColor=#ffffff>'
cHtml+='<DIV><FONT size=2 face=Arial>'+p1+'</FONT></DIV></BODY></HTML>'

TRY
oEmailCfg := CREATEOBJECT( "CDO.Configuration" )
WITH OBJECT oEmailCfg:Fields
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ):Value := "smtp.gmail.com"
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ):Value := 465
:Item( "http://schemas.microsoft.com/cdo/configuration/sendusing" ):Value := 2 // Remote SMTP = 2, local = 1
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value := .T.
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpusessl" ):Value := .T.
:Item( "http://schemas.microsoft.com/cdo/configuration/sendusername" ):Value := "test@gmail.com"
:Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ):Value := "test123" // Password
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"):Value := 30
:Update()
END WITH
CATCH oError
MsgInfo( "Could not send message" + ";" + ;
"Error: " + TRANSFORM(oError:GenCode, NIL) + ";" + ;
"SubC: " + TRANSFORM(oError:SubCode, NIL) + ";" + ;
"OSCode: " + TRANSFORM(oError:OsCode, NIL) + ";" + ;
"SubSystem: " + TRANSFORM(oError:SubSystem, NIL) + ";" + ;
"Message: " + oError:Description )
END
oError:=NIL

TRY
oEmailMsg := CREATEOBJECT ( "CDO.Message" )
WITH OBJECT oEmailMsg
:Configuration = oEmailCfg
:From = chr(34)+"Ph Jacquet "+chr(34)+ "<jacquetlg@gmail.com>" // This will be displayed in the From (The email id does not appear)
:To = "ph.jacquet@skynet.be;test@testmail.be" // <----- Place your email address
:Subject = "Mailing Résultats Nephrologie"
:AddAttachment("n:\tables\bio_tx\info.txt")
:MDNRequested = .T.
:HTMLBody = cHtml
END WITH
oEmailMsg:Send()
CATCH oError
MsgInfo("Could not send message" + ";" + CRLF+ ;
"Error: " + TRANSFORM(oError:GenCode, NIL) + ";" + CRLF+;
"SubC: " + TRANSFORM(oError:SubCode, NIL) + ";" + CRLF+ ;
"OSCode: "+ TRANSFORM(oError:OsCode, NIL) + ";" + CRLF +;
"SubSystem: " + TRANSFORM(oError:SubSystem, NIL) + ";" +CRLF+ ;
"Message: " + oError:Description )
END
*MsgInfo("Reached the end of the code")

return .T.
Jack
 
Posts: 288
Joined: Wed Jul 11, 2007 11:06 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 40 guests