How do I authenticate using a Gmail account?
Grateful.
FHW 8.11 + xHarbour
How do I authenticate using a Gmail account?
Grateful.
Use port 465
Dear MR.Alexandre,
Here is a Sample code to send Email using Gmail.
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 WITHRegards
Anser
Error description: Error CDO.Message/3 Â DISP_E_MEMBERNOTFOUND: SENDDear Mr.Ramesh,
Please use TRY CATCH, it seems that the object is not created properly. Please note that u need active internet connection while testing the email send application.
It is working fine here.
Regards
Anser
How to pass parameters ?
How to attach files ?
Thanks .
Dear Mr.Jack,
How to pass parameters ?
What do you mean by 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 WITHRegards
Anser
Hello Anser,
I tried with TRY, CATCH but I am getting the error exactly at :Send() method.
I am already connected to Internet, while I was testing this and I checked the
creation of all Objects. They are created properly.
I dont't know what is going wrong ?
Dear Ramesh,
Here is a complete sample which is working for me here. You need to provide only your gmail id and password in the code. If this is not working then, I believe that your firewall must be blocking the port 465. You may also try to increase the timeout value from 30 to some higher values
For Eg.
: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.Regards
Anser
Hello Anser,
Thank you very much for your example and detailed suggestions.
Your recent example has worked. And I could send my test mail.
Thank you.
Problem solved.
[]s
Alexandre
Is it also possible to read the Inbox of Gmail and save attached files ?
Thanks .
Hi Mr.Jack,
As per Microsoft, GetStream() returns the Stream object containing the complete message, including headers and all content, in serialized (wire-transport) format. I am not sure and I have not yet tried it. The information may be useful to you.
For Ref.
http://msdn.microsoft.com/en-us/library/ms526453(EXCHG.10).aspx
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")Regards
Anser