How do I authenticate using a Gmail account?
Grateful.
oMailer:oEmailCfg := CREATEOBJECT( "CDO.Configuration" )
WITH OBJECT oMailer: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 := oMailer:cSendMailId // Gmail A/c ID
:Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ):Value := oMailer:cSendMailIdPass // Password
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"):Value := 30
:Update()
END WITH
oEmailMsg := CREATEOBJECT ( "CDO.Message" )
WITH OBJECT oEmailMsg
:Configuration = oMailer:oEmailCfg
:From = chr(34)+" "+oMailer:cFromName+" "+chr(34)+ "<"+oMailer:cFromID+">" // This will be displayed as From address
:To = cToEmailId // To Email ID
:BCC = cBcc // BCC Id
:Subject = oMailer:cSubject
:Send()
END WITH
Error description: Error CDO.Message/3 DISP_E_MEMBERNOTFOUND: SEND
How to pass parameters ?
How to attach files ?
oEmailMsg := CREATEOBJECT ( "CDO.Message" )
WITH OBJECT oEmailMsg
:Configuration = oEmailCfg
:From = chr(34)+" "+cFromName+" "+chr(34)+ "<"+cFromID+">" // This will be displayed as From address
:To = cToEmailId // To Email ID
:BCC = cBcc // BCC Id
:Subject = cSubject
:AddAttachment(cAttachment) // Add attachment "c:\LCd Projector.txt"
:Send()
END WITH
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"):Value := 60
#Include "FiveWin.Ch"
*-------------------------------------------------*
Function Main()
*-------------------------------------------------*
Local oEmailCfg,oEmailMsg,oError,cHtml
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>Hello How are you ?</FONT></DIV></BODY></HTML>'
MSgInfo("I am going to Send Message")
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 := "YourGmailId@gmail.com"
:Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ):Value := "YourGmailPassword" // 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)+"Anser Test "+chr(34)+ "<anserkk@gmail.com>" // This will be displayed in the From (The email id does not appear)
:To = "anserkk@hotmail.com" // <----- Place your email address
:Subject = "Test Message"
: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.
Local iMsg,iDSrc,iBp
// Get the IMessage interface (Dispatch)
iMsg = CreateObject("CDO.Message")
// Get the IDataSource on the Message Object (IDispatch)
iDSrc = iMsg:GetInterface("IDataSource")
//Get the IBodyPart interface on the Message Object (IDispatch)
iBp = iMsg:GetInterface("IBodyPart")
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 47 guests