Page 2 of 2

Re: [Done] 5.40LTS Cannot send mail with TLS/Asynchronous

Posted: Sat Oct 24, 2015 10:10 pm
by RichAlgeni
If anyone needs another example, just replace the data in variables userName, mailFrom and password. It works beautifully:

Code: Select all

; process to test new email capabilities in PB 5.40

EnableExplicit

; open the console window, initialize the network, send the message, then quit

InitNetwork()

OpenConsole()

Define result.i
Define mailNumber.i
Define mailHost.s     = "smtp.gmail.com"
Define userName.s     = "your_email_address@gmail.com"
Define mailFrom.s     = "your_email_address@gmail.com"
Define password.s     = "your_password_here"
Define mailPort.i     = 587
Define mailTo.s       = "your_destination@destination.com"
Define subject.s      = "64 bit email Test using TLS Encryption"
Define emailBody.s    = "Dear Sir/Madam, this email is brought to you courtesy of 64 bit PureBasic Version 5.40 TLS Encryption."

PrintN("SendEmail() > About to create mail!")

mailNumber = CreateMail(#PB_Any, userName, subject)
If mailNumber > 0
    AddMailRecipient(mailNumber, mailTo, #PB_Mail_To)
    SetMailBody(mailNumber, emailBody)
    result = SendMail(mailNumber, mailHost, mailPort, #PB_Mail_UseSSL, userName, password)
    FreeMail(mailNumber)

    PrintN("SendEmail() > completed, return value: " + Str(result))
Else
    PrintN("SendEmail() > error creating mail process")
EndIf

Input()

CloseConsole()
Port 587 must tell PureBasic to use TLS Encryption. For less secure SSL, use port 465.

See for more information: http://stackoverflow.com/questions/1579 ... 65-and-587

Re: [Done] 5.40LTS Cannot send mail with TLS/Asynchronous

Posted: Sat Oct 24, 2015 10:15 pm
by netmaestro
Google prevents my sign-in attempt every time. I have to find the setting in my profile to loosen that up.

Re: [Done] 5.40LTS Cannot send mail with TLS/Asynchronous

Posted: Sat Oct 24, 2015 10:32 pm
by skywalk
Same here. No go with either port. :?

Re: [Done] 5.40LTS Cannot send mail with TLS/Asynchronous

Posted: Sun Oct 25, 2015 4:09 am
by netmaestro
I finally got irritated enough to go find the setting in gmail. It is under Settings->Accounts and Import->Other Google account settings->Connected apps and sites->Allow less secure apps:ON

Once I found the setting and turned it on, the RichAlgeni code works without problem. But I'm going to guess that because this mail is machine-produced it would go to people's spam folder first unless the recipient had the sender whitelisted, correct? Anyone know for sure?

Re: [Done] 5.40LTS Cannot send mail with TLS/Asynchronous

Posted: Sun Oct 25, 2015 9:17 am
by Fangbeast
I never knew that setting existed so never touched it. So why does my email from PB work when others have failed??

Why is my setup okay when others just fail? Should I do a screen dump of my gmail settings so people can compare in case they are accessing a different setup somehow?

After Fred did that SSL fix, it has just worked ever since.

(Scratching head)

Re: [Done] 5.40LTS Cannot send mail with TLS/Asynchronous

Posted: Sun Oct 25, 2015 12:30 pm
by IdeasVacuum
Should I do a screen dump of my gmail settings
I think that would be a great help 8)

Re: [Done] 5.40LTS Cannot send mail with TLS/Asynchronous

Posted: Sun Oct 25, 2015 5:56 pm
by skywalk
Thanks netmaestro :)
Above code works with Port 587(465 fails) if I change the gmail setting:
; https://myaccount.google.com/security?hl=en#activity
; Access for less secure apps has been turned = ON.

Re: [Done] 5.40LTS Cannot send mail with TLS/Asynchronous

Posted: Mon Oct 26, 2015 10:51 pm
by RichAlgeni
Fangbeast wrote:I never knew that setting existed so never touched it. So why does my email from PB work when others have failed??

Why is my setup okay when others just fail? Should I do a screen dump of my gmail settings so people can compare in case they are accessing a different setup somehow?

After Fred did that SSL fix, it has just worked ever since.

(Scratching head)
I've had my Google email account for years, the SSL and TLS code has worked fine for me since 2013.

Re: [Done] 5.40LTS Cannot send mail with TLS/Asynchronous

Posted: Tue Oct 27, 2015 1:23 am
by Fangbeast
RichAlgeni wrote:
Fangbeast wrote:I never knew that setting existed so never touched it. So why does my email from PB work when others have failed??

Why is my setup okay when others just fail? Should I do a screen dump of my gmail settings so people can compare in case they are accessing a different setup somehow?

After Fred did that SSL fix, it has just worked ever since.

(Scratching head)
I've had my Google email account for years, the SSL and TLS code has worked fine for me since 2013.
Mine didn't work with the initial PB 5.40 release, I reported it, Fred fixed something and then it did. I've had a Google email account since they released it and never changed any settings either.

Re: 5.40LTS Cannot send mail with TLS/Asynchronous

Posted: Wed Apr 06, 2016 8:23 pm
by RichardL
Hi,
I used the code by RichAlgeni (with my name and account details etc) and it worked first go. Good!
But... when I added a 'cc' and a 'jpg' or 'PDF' attachment the email body text disappears, just the attachment shows in ThunderBird.
Any idea what I'm likely to be doing wrong?
I'm using PB5.41LTS

RichardL

Code: Select all

EnableExplicit

InitNetwork()
OpenConsole()

Define CRLF.s = Chr(13)+Chr(10)
Define result.i
Define mailNumber.i
Define mailHost.s     = "smtp.gmail.com"

Define userName.s    = "xxxxxxxxxxxx"
Define mailFrom.s     = "xxxxxxxxxxxx"
Define Password.s     = "xxxxxxxxxxxx"
Define mailTo.s         = "xxxxxxxxxxxx"
Define ccmailTo.s      = "xxxxxxxxxxxx"
Define subject.s      = "Ermintrude will be late."
Define emailBody.s    
Define mailPort.i     = 587
emailBody = "This email was sent automatically by a prototype email sender. 01"+CRLF
emailBody + "This email was sent automatically by a prototype email sender. 02"+CRLF
emailBody + "This email was sent automatically by a prototype email sender. 03"+CRLF
emailBody + "This email was sent automatically by a prototype email sender. 04"+CRLF
emailBody + "This email was sent automatically by a prototype email sender. 05"+CRLF
emailBody + "This email was sent automatically..... and made longer..."

PrintN("SendEmail() > About to create mail!")

mailNumber = CreateMail(#PB_Any, userName, subject)
If mailNumber > 0
  AddMailAttachment(mailNumber, "Knockers.pdf","C:\temp\Intact_020415163929547.pdf")
  SetMailBody(mailNumber, emailBody)
  AddMailRecipient(mailNumber, mailTo , #PB_Mail_To)
  AddMailRecipient(mailNumber,ccmailTo, #PB_Mail_Cc)
  result = SendMail(mailNumber, mailHost, mailPort, #PB_Mail_UseSSL, userName, Password)
  FreeMail(mailNumber)
   PrintN("SendEmail() > completed, return value: " + Str(result))
Else
  PrintN("SendEmail() > error creating mail process")
EndIf

Input()

CloseConsole()

Re: 5.40LTS Cannot send mail with TLS/Asynchronous

Posted: Wed Apr 06, 2016 9:34 pm
by bbanelli
@RichardL

Confirmed in 5.42 x86 (Windows 7). No body is shown if attachment is enabled. Perhaps you should move this to bugs section?

Re: 5.40LTS Cannot send mail with TLS/Asynchronous

Posted: Wed Apr 06, 2016 11:30 pm
by RichAlgeni
Confirmed with 5.42 x64.

Re: 5.40LTS Cannot send mail with TLS/Asynchronous

Posted: Thu Apr 07, 2016 12:02 am
by RichAlgeni