From Xojo Documentation

Revision as of 18:55, 19 November 2009 by (talk) (Examples)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


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

Super Class



Name Type Description
Attachments EmailAttachment() The array of EmailAttachments that are attached to this email message.
BCCAddress String Returns a comma-separated list of Strings. Gets the BCC addresses for this email.
BodyEnriched String The body text of the email message in enriched format.

Some clients such as Mail use this format when sending styled emails.

BodyHTML String The body text of the email as HTML.
BodyPlainText String The body text of the email as plain text.

Clients that do not support HTML or enriched format will display the message as plain text using the contents of this property.

CCAddress String Returns a comma-separated list of Strings. Gets the CC addresses for this email.
FromAddress String Gets or sets a String containing the address the email is coming from.
Headers EmailHeaders The headers for this email message.
Source String A String containing the raw source of the email message.
Subject String Gets or sets the subject of the email.
ToAddress String Gets the addresses for this email and returns a comma-separated list of Strings.


Name Parameters Description
AddBCCRecipient Recipient as String Adds a BCC recipient to the email.
AddCCRecipient Recipient as String Adds a CC recipient to the email.
AddRecipient Recipient as String Adds a recipient to the email.


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. The TextFields named fromAddressfld, subjectFld, bodyFld, and htmlFld contain this information:

Dim mail as emailMessage
Dim s as string
// set up the socket--Socket1 is an SMTPSocket
socket1.address = serverFld.text
socket1.port = 25
if authenticateBox.value = true then
socket1.username = usernameFld.text
socket1.password = passwordFld.text
socket1.username = ""

Dim mail as =New EmailMessage
mail.bodyPlainText = bodyFld.text
mail.bodyHTML = htmlFld.text
mail.headers.appendHeader "X-Mailer","REALbasic SMTP Demo"

// add recipients
s = replaceAll(toAddressFld.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(ccAddressFld.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))
// add attachments
if fileFld.text <> "" then
file.loadFromFile getFolderItem(fileFld.text)
mail.attachments.append file

// send the email
socket1.messages.append mail
progressBar1.visible = true

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 =serverFld.text
socket1.port =110

socket1.username = usernameFld.text
socket1.password = passwordFld.text

me.caption = "Disconnect"
me.caption = "Connect"
end if

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

Dim s as string

// display the message
s = email.bodyHTML
if s = "" then
s = email.bodyPlainText

bodyFld.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.