UserGuide

Email

From Xojo Documentation

You can send email using SMTP (Standard Mail Transfer Protocol) protocol and receive email using POP3 (Post Office Protocol) protocol.

Sending Email

To send email, you use the SMTPSecureSocket class. Before you can send an email, you need to create the email message. You do this using the EmailMessage class.

You have to provide your own SMTP server to actually send the email. You can choose to use your ISP mail server or a 3rd party server such as Gmail. Most SMTP servers will require you to log on with a username and password and require a secure connect.

In order to use Gmail to send 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, this code is able to send a simple email:

MailSocket.Address = "smtp.gmail.com"
MailSocket.Port = 465
MailSocket.ConnectionType = SMTPSecureSocket.TLSv1
MailSocket.SMTPConnectionMode = SMTPSecureSocket.ModeSSLTLS
MailSocket.Secure = True
MailSocket.UserName = <YourGmailUserName>
MailSocket.Password = <YourGmailPassword>

Dim email As New EmailMessage
email.FromAddress = "paul@xojo.com"
email.Subject = "Hello, world!"
email.BodyPlainText = "I love Xojo!"
email.AddRecipient("hello@xojo.com")

MailSocket.Messages.Append(email)
MailSocket.SendMail

The EmailMessage class has even more properties and methods to set HTML message text, headers and CC recipients.

You can also add attachments to your email using the EmailAttachment class.

Sending Email

Receiving Email

To receive email, you use the POP3SecureSocket class. This class connects to your POP3 server and requests mail messages. As messages are received, the MessageReceived event handler is called with the email supplied as an EmailMessage parameter.

POP3SecureSocket has many events, properties and methods to allow you to receive POP3 email.

fa-info-circle-32.png
Many email services use IMAP instead of POP. If you need IMAP, consider looking into the MonkeyBread Software Plugin.

Example Projects

  • Examples/Communication/Internet/Email/iOSSendMail
  • Examples/Communication/Internet/Email/SimpleSendMail
  • Examples/Communication/Internet/Email/SMTPSecureSocketExample
  • Examples/Communication/Internet/Email/WebSimpleSendEmail

See Also

EmailMessage, EmailAttachment, SMTPSecureSocket classes; UserGuide:Framework topic