SMTPSocket.SendMail

From Xojo Documentation

Method

SMTPSocket.SendMail()

Supported for all project types and targets.

Connects to the mail server, sends the messages in the queue, and disconnects.

Notes

This method works asynchronously. So keep the reference to this SMTPSocket object alive while mail is sent: e.g. as a property of a window.

Sample Code

This example is the Action event of the Send button on the Send Mail Demo main window. It sends the new message after adding it to the array of messages.

Dim mail As EmailMessage

// set up the socket
Socket1.Address = "smtp.myserver.com"
Socket1.Port = 25

Socket1.UserName = "<username>"
Socket1.Password = "<password>"

// populate the email message
mail = New EmailMessage
mail.FromAddress = "test@testsite.org"
mail.Subject = "My Subject"
mail.BodyPlainText = "Hello!"
mail.Headers.AppendHeader("X-Mailer","SMTP Test")

// send the email
Socket1.Messages.Append(mail)
Socket1.SendMail