First, you must understand that you can't use your normal Gmail password with SMTP. You have to create an app-specific password instead, through your Gmail Account settings, like so:
You'll then get a custom password for use with your device (or in our case, our PureBasic app):
If you need a more detailed tutorial on creating app passwords, then click here:
https://www.lifewire.com/get-a-password ... -2-1171882
Then, all you need to do is configure PureBasic's mail settings as below to send mail through Gmail's SMTP, without needing to change or lower Gmail's default security settings, etc.
Regarding the port number: only 465 works for me, but only 587 works for others; so try both if one fails.
Hope this tip helps someone.
Code: Select all
recipient$="recipient@somewhere.com"
sender_login$="sender@gmail.com"
sender_password$="gmail-app-password"
sender_port=465 ; Try 587 if 465 fails.
InitNetwork()
If CreateMail(0, sender_login$, "Hello !")
SetMailBody(0, "Hello !" + #CRLF$ +
"This is a multi-" + #CRLF$ +
"line mail !")
AddMailRecipient(0, recipient$, #PB_Mail_To)
Result = SendMail(0, "smtp.gmail.com", sender_port, #PB_Mail_Asynchronous | #PB_Mail_UseSSL, sender_login$, sender_password$)
Repeat
Progress = MailProgress(0)
Delay(1000)
Until Progress = #PB_Mail_Finished Or Progress = #PB_Mail_Error
If Progress = #PB_Mail_Finished
MessageRequester("Information", "Mail correctly sent !")
Else
MessageRequester("Error", "Can't sent the mail !")
EndIf
EndIf