Send Email via Gmail SMTP

I had a very similar function working a couple years ago but now I can’t send an email using the gmail SMTP server.

I DO have the ‘use less secure apps’ switch turned on.

I execute the following code, the LastErrorCode is 0 but the email is never delivered to the recipient’s inbox. It just disappears.

Has gmail changed some of the required settings or what else could be wrong?

[code]Dim oMail As EmailMessage
Dim i As Integer
Dim s As String
dim sMessage1 As String
dim sMessage2 As String
dim sMessage3 As String
dim sMessageFull As String

sMessage1 = "Greetings Brother " + oMember.sFirstName + Chr(10) + Chr(10)
sMessage2 = taMessage.Text + Chr(10) + Chr(10)
sMessage3 = taSignature.Text
sMessageFull = sMessage1 + sMessage2 + sMessage3

MailSocket.Address = “smtp.gmail.com
MailSocket.Port = 465
MailSocket.ConnectionType = SMTPSecureSocket.TLSv1
MailSocket.SMTPConnectionType = SMTPSecureSocket.SMTPConnectionTypes.SSLTLS
MailSocket.Secure = True

MailSocket.Username = sSMTPAccount
MailSocket.Password = sSMTPPassword

oMail = New EmailMessage
oMail.FromAddress = “@gmail.com"
oMail.AddRecipient("
*@gmail.com”)
oMail.Subject = tfSubject.Text
oMail.BodyPlainText = sMessageFull
oMail.Headers.AppendHeader(“X-Mailer”,“SMTP Test”)

MailSocket.Messages.Append(oMail)
MailSocket.SendMail

i = MailSocket.LastErrorCode
s = "Message Result = " + Str(i)
MsgBox(s)

if i = 0 then
lblResult.Visible = True
lblResult.Text = “Successful”
lblResult.TextColor = Color.Blue
else
lblResult.Visible = True
lblResult.Text = “Failed”
lblResult.TextColor = Color.Red
end if
[/code]

maybe a firewall issue at your pc?

i got a security warning in google mail first mail.google.com . (and LastErrorCode=0)
then i enable less secure apps here
myaccount.google.com/security
then the mailing works for me.
username was my mail adress.
MailSocket = SMTPSecureSocket in a Window

i used xojo 2019r3.1

This is done and I don’t get any kind of warning, neither is it in my spam folder.

you had set a break point and looked if this is filled?

sSMTPAccount sSMTPPassword

or google blocked your ip because of testing a lot before switch to allow unsecure apps?

Yes I have used break points extensively

How do I determine if google has blocked my ip?

[quote=473384:@William Plunkett]Yes I have used break points extensively

How do I determine if google has blocked my ip?[/quote]

i don’t know but if you restart your router maybe you got a new ip.

A good place to start looking for blocked ip addresses is https://www.spamhaus.org/lookup/

And you have set up and are using an app-specific password?

Try:

if MailSocket.port = 587 then
MailSocket.SMTPConnectionType = SMTPSecureSocket.SMTPConnectionTypes.STARTTLS
else
MailSocket.SMTPConnectionType = SMTPSecureSocket.SMTPConnectionTypes.SSLTLS
end if

MailSocket.ConnectionType = SMTPSecureSocket.TLSv1 should be

MailSocket.ConnectionType     = SMTPSecureSocket.TLSv12

Just a heads up. Google will soon (not yet) be getting rid of LSA and requiring OAuth.