Help: Errors with SMTPSecureSocket and gmail

Hello,

i’m new to Xojo and i am reading the “Introduction to Programming with Xojo” from this Xojo Site.
At chapter 11.5 of the book there is a code example for sending mails with SMTPSecureSocket. I have first tried sending a mail using the code
for “Google Mail” as in the book, then i changed the code to the following (after reading some posts in the forum):

  MailSocket.Address = "smtp.gmail.com"
  MailSocket.Username = "myusername@googlemail.com"
  MailSocket.Password = "mypassword"
  MailSocket.Port = 587
  MailSocket.ConnectionType = SMTPSecureSocket.TLSv1
  MailSocket.Secure = true
 
 Dim Start as New Date
  
  While 1=1
    MailSocket.Connect
    Dim Now as New Date
    if Now.TotalSeconds - Start.TotalSeconds > 60 Then Exit
    if MailSocket.IsConnected Then Exit
  Wend
  
  SendTheMessage

The method “SendTheMessage” is:

  Dim m As EmailMessage
  m = New EmailMessage 
  m.AddRecipient(ToField.Text) 
  m.Subject = SubjectField.Text 
  m.BodyPlainText =MessageField.Text
  m.FromAddress = "myusername@googlemail.com"
  MailSocket.Messages.Append(m)
  MailSocket.SendMail

But i always get a lot of SMTP ERROR: Password command failed:

[quote]534-5.7.14 …
534-5.7.14 … Please log in via your web browser and
534-5.7.14 then try again.
534-5.7.14 Learn more at
534 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754[/quote]

At this google site you can read the following:

[quote]If you’re still having problems, visit http://www.google.com/accounts/DisplayUnlockCaptcha and
sign in with your Gmail username and password. If necessary, enter the letters in the distorted picture.

Your mail app might not support the latest security standards. Learn how to allow less secure apps access to your account.[/quote]
The first solution didn’t work at all and the second one gives me this link to a site where i can “activate access for less secure apps”. But i don’t want to lower the security for my gmail account.

I looked at the security information of my gmail account in chrome browser:
mail.google.com uses TLS 1.2 with a 128bit encryption
the connection is encrypted and authenticated with AES_128_GCM
RSA is used for key-exchange

So, can anyone please tell me how to write the code to be able to send messages with SMTPSecureSocket and my googlemail account -
or doesn’t XOJO support the latest security standards in their SMTPSecureSocket.TLS implementation yet ?

Greetings from Germany
Ralf

I have several deployed apps that send mail via gmail.

Although Xojo is not at TLS1.2 yet using Xojo’s TLSv1 setting will work.

If it’s not for you, the problem is elsewhere.

Did you enable SMPT for your gmail account? By default only IMAP is enabled.

  • Karen

Hello Karen,

thanks for your reply.

“Enable SMTP” ??? - I now use gmail for years but i never ever have seen a setting in gmail where to enable SMTP.
In gmail one can enable or disable Pop3 and IMAP but no SMTP. So if you really have a gmail account then please
tell me where to find the option to enable SMPT as you suggested.

-Ralf

[quote=140060:@Karen Atkocius]Did you enable SMPT for your gmail account? By default only IMAP is enabled.

  • Karen[/quote]
    I think you have that reversed. You have to enable IMAP. SMTP is the default.

By the way, i POP3 and IMAp is enabled in my gmail account.

-Ralf

If so then my company (We use company GMail accounts) set it up the other way because I had to enable SMPT on the account to be able to send email through it

Sorry. Red herring. IMAP is a mechanism to receive messages (as an alternative to POP3). You still use smtp to send.

I can send email via smtp.gmail.com using port 587 and TLSv1, so Karen is right, your problem is somewhere else.

@Tim Hare

Can you please log in to google (at google search site) and then open this link - please tell me what option button is activated at this site.

-Ralf

I have access for less secure apps Enabled. If I disable it, I can no longer send email. I think you found the issue.

@Tim Hare

I thought as much that this is the problem but i don’t want to lower my gmail security.
I think it’s to XOJO to implement the newest security standards to the SMTPSecureSocket in a next version of Xojo.

But maybe someone knows a solution for now to send emails by gmail account with “access for less secure apps” disabled ?

-Ralf

See:

<https://xojo.com/issue/31126>

@Karen Atkocius

When i click on the link nothing happens. How can i read that Feddback Case ?

-Ralf

[quote=140191:@Ralf Zrenner]@Karen Atkocius

When i click on the link nothing happens. How can i read that Feddback Case ?

-Ralf[/quote]

You will need to have the Feedback App installed.
Look here