Author Topic: SMTP & GMAIL  (Read 4304 times)

JTaylor

  • Pundit
  • *****
  • Posts: 1014
    • Data & Stuff Inc.
SMTP & GMAIL
« on: December 08, 2014, 10:06:26 pm »
The following code worked fine until recently using port 25.   Now it tells me it can't authenticate.   If I use the recommended port 465 it doesn't give me an error but it eventually times out.   Anyone have any code that works with GMAIL for SMTP mail?   I've enabled the POP mail setting on the email account.  Other suggestions?   Thanks.

Jim

Code: Winbatch
rqm_user = '....@gmail.com'
rqm_pw_word = '........'
whoto = '...............com'
whofrom = '....@gmail.com'
msg = "HELLO WORLD"
subj    = "Hello World"
port    = 465
rqm_smtpserver = "smtp.gmail.com"

  IntControl(73, 2, @TRUE,"",0)
  ObjectClrOption("use","System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")  
  _TRUE                  = ObjectType( "BOOL", @TRUE )
  _FALSE                 = ObjectType( "BOOL", @FALSE )
 
  NetworkCredential      = ObjectClrNew( 'System.Net.NetworkCredential', rqm_user, rqm_pw_word)
 
  MailAddress_From       = ObjectClrNew( 'System.Net.Mail.MailAddress', whofrom )
  MailAddress_To         = ObjectClrNew( 'System.Net.Mail.MailAddress', StrTrim(ItemExtract(1,whoto,"|")))

  MailMessage            = ObjectClrNew( 'System.Net.Mail.MailMessage', MailAddress_From, MailAddress_To )

  whoto2 = ""
  If ItemCount(whoto,"|") > 1 Then
    For mailcnt = 2 to ItemCount(whoto,"|")
      whoto2 = StrTrim(ItemExtract(mailcnt,whoto,"|"))
      If ItemCount(whoto2,"@") > 1 Then MailMessage.To.Add(whoto2)
    Next
  EndIf

  MailMessage.IsBodyHtml = _TRUE
  MailMessage.Subject    = subj
  MailMessage.Body       = msg
 
  SmtpClient             = ObjectClrNew('System.Net.Mail.SmtpClient')
  SmtpClient.Host        = rqm_smtpserver
  If StrTrim(port) == "" Then port = 25
  port                   = port+0
  SmtpClient.Port        = port
  SmtpClient.Credentials = NetworkCredential  ; Authentication
  SmtpClient.EnableSsl   = _TRUE              ; Use SSL
  rc = "Failed"
message("HI","")
  SmtpClient.Send(MailMessage)                ; Send

  Return

  :WBERRORHANDLER

    message("Error","There seems to be a problem...")
    Exit
  Return


 

td

  • Tech Support
  • *****
  • Posts: 3016
    • WinBatch
Re: SMTP & GMAIL
« Reply #1 on: December 09, 2014, 06:41:12 am »
Try port 587.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

JTaylor

  • Pundit
  • *****
  • Posts: 1014
    • Data & Stuff Inc.
Re: SMTP & GMAIL
« Reply #2 on: December 09, 2014, 07:00:03 am »
I get the same message I get with port 25 and bad login info.   I've also turned off my [software] firewall but get the same results.

Jim

"COM/CLR Exception:

    System
    The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at"

td

  • Tech Support
  • *****
  • Posts: 3016
    • WinBatch
Re: SMTP & GMAIL
« Reply #3 on: December 09, 2014, 07:18:42 am »
Then you haven't modified your gmail account settings to allow less secure apps to access your gmail account.  Google is becoming more and more like the old Microsoft.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

  • Tech Support
  • *****
  • Posts: 3016
    • WinBatch
Re: SMTP & GMAIL
« Reply #4 on: December 09, 2014, 07:37:22 am »
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

JTaylor

  • Pundit
  • *****
  • Posts: 1014
    • Data & Stuff Inc.
Re: SMTP & GMAIL
« Reply #5 on: December 09, 2014, 07:41:17 am »
You beat me to it.   Finally found that little caveat in the Help section.   Once I enable that option and use port 587 it works.  Thanks.

Jim

Then you haven't modified your gmail account settings to allow less secure apps to access your gmail account.  Google is becoming more and more like the old Microsoft.