SMTPSocket.SendMail

From Xojo Documentation

Revision as of 14:25, 26 October 2018 by PLefebvre (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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