From Xojo Documentation

Class (inherits from Object)

Used to hold the contents of an email message and its enclosures, if any.

Attachments BodyPlainText Source
BCCAddress fa-lock-32.png CCAddress fa-lock-32.png Subject
BodyEnriched FromAddress ToAddress
BodyHTML Headers

AddBCCRecipient AddCCRecipient AddRecipient


The following example sets the values of the From Address, Subject, Body, and Headers from the values of the Text properties of TextFields in a window.

// set up the socket--Socket1 is an SMTPSocket
Socket1.Address = ServerField.Text
Socket1.Port = 25
If AuthenticateBox.Value = True Then
Socket1.UserName = UserNameField.Text
Socket1.Password = PasswordField.Text
Socket1.UserName = ""
End If

Dim mail As New EmailMessage
mail.FromAddress = FromAddressField.Text
mail.Subject = SubjectField.Text
mail.BodyPlainText = BodyField.Text
mail.BodyHTML = HtmlField.Text
mail.Headers.AppendHeader("X-Mailer","Example SMTP Demo")

Dim i As Integer
Dim s As String

// add recipients
s = ReplaceAll(ToAddressField.Text, ",", Chr(13))
s = ReplaceAll(s, Chr(13) + Chr(10), Chr(13))
For i = 1 To CountFields(s, Chr(13))
mail.AddRecipient(Trim(NthField(s, Chr(13), i)))

// add cc recipients
s = ReplaceAll(CCAddressField.text, ",", Chr(13))
s = ReplaceAll(s, Chr(13) + Chr(10), Chr(13))
For i = 1 To CountFields(s, Chr(13))
mail.AddCCRecipient(Trim(NthField(s, Chr(13), i)))

Dim file As EmailAttachment

// add attachments
If fileField.Text <> "" Then
file = New EmailAttachment
End If

// send the email

The Action event of a PushButton connects to a POP3 server and gets the email for the specified account. It reads the POP3Server, username, and password from TextFields on the form. Socket1 is a POP3Socket object.

If Me.Caption = "Connect" Then
Socket1.Address = ServerField.Text
Socket1.Port = 110

Socket1.UserName = UserNameField.Text
Socket1.Password = PasswordField.Text

Me.Caption = "Disconnect"
Me.Caption = "Connect"
End If

The MessageReceived event of the POP3Socket places the text of the message in a TextField.

Dim s As String

// display the message
s = Email.BodyHTML
If s = "" Then
s = Email.BodyPlainText
End If

BodyField.Text = ReplaceAll(s, Chr(13) + Chr(10), Chr(13))

See also the examples for the POP3Socket class.

See Also

EmailAttachment, EmailHeaders, HTTPSecureSocket, HTTPSocket, POP3SecureSocket, POP3Socket, SMTPSecureSocket, SMTPSocket, SocketCore, SSLSocket, TCPSocket classes.