EmailMessage

From Xojo Documentation
Jump to: navigation, search

Class (inherits from Object)

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



Properties
Attachments BodyPlainText Source
BCCAddress CCAddress Subject
BodyEnriched FromAddress ToAddress
BodyHTML Headers


Methods
AddBCCRecipient AddCCRecipient AddRecipient


Examples

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 file as EmailAttachment
Dim i as Integer
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
else
socket1.username = ""
end

Dim mail as =New EmailMessage
mail.fromAddress=fromAddressFld.text
mail.subject=subjectFld.text
mail.bodyPlainText = bodyFld.text
mail.bodyHTML = htmlFld.text
mail.headers.appendHeader "X-Mailer","Example 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))
next
// 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))
next
// add attachments
If fileFld.text <> "" then
file = New EmailAttachment
file.loadFromFile GetFolderItem(fileFld.text)
mail.attachments.append file
end

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


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

socket1.connect
Me.caption = "Disconnect"
else
socket1.disconnectFromServer
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
end

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.

Personal tools
Namespaces

Variants
Actions
Main
Content
Starting Out
Dig Deeper
More Help
Toolbox
About