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:

Dim oMail As EmailMessage
Dim i As Integer
Dim s As String

MailSocket.Address = trim(tfServer.Text) //
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 = “
oMail.Subject = tfSubject.Text
oMail.BodyPlainText = taMessage.Text
oMail.Headers.AppendHeader(“X-Mailer”,“LSA SMTP Demo”)


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

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.


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 = "" 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:

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.