Send Email SMTP & Gmail

I’m trying to use the EmailMessage and SMTPSecureSocket Classes to send email via the Gmail outgoing Server. I am using the following method after the fields are completed on the form:

[code]
Dim oMail As EmailMessage
Dim i As Integer
Dim s As String

MailSocket.Address = trim(tfServer.Text) // smtp.gmail.com
MailSocket.Port = 25
MailSocket.Username = trim(tfUserName.Text)
MailSocket.Password = trim(tfPassword.Text)
MailSocket.Secure = True
MailSocket.ConnectionType = SSLSocket.TLSv1

oMail = New EmailMessage
oMail.FromAddress = “ashXXXXXXX1138@gmail.com
oMail.Subject = tfSubject.Text
oMail.BodyPlainText = taMessage.Text
oMail.Headers.AppendHeader(“X-Mailer”,“LSA SMTP Demo”)
oMail.AddRecipient(trim(tfTo.Text))

MailSocket.Messages.Append(oMail)
MailSocket.SendMail

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

Return [/code]

have attempted with and without the MailSocket.Secure = True and MailSocket.ConnectionType = SSLSocket.TLSv1 statements.

Tracing the code and checking the values in the debugger, everything appears correct and the resulting msgbox says the return code is 0 or no error.

Yet the message never arrives.

Can someone please tell me how to make this work.

thanks,

GMail has special authorization things, does your account allow for connections from “insecure applications” ?

I use these settings to connect & send email through my gmail account

SendSocket = New SMTPSecureSocket SendSocket.Secure = True SendSocket.SMTPConnectionMode = SendSocket.SSLv23 SendSocket.Username = Username SendSocket.Password = Password SendSocket.Address = "smtp.gmail.com" SendSocket.Port = 465

In order to connect to Gmail you’ll need to enable the “allow less secure apps” option as described in this Google support document:
https://support.google.com/accounts/answer/6010255

With that enabled, these settings work for most users:

MailSocket.Port = 465 MailSocket.ConnectionType = SMTPSecureSocket.TLSv1 MailSocket.SMTPConnectionMode = SMTPSecureSocket.ModeSSLTLS MailSocket.Secure = True

Also see: Examples/Communication/Internet/EmailSSLExample

Paul: Thanks, worked perfectly.