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 ReadOnlyProperty.png CCAddress ReadOnlyProperty.png 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.

// 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
Else
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)))
Next

// 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)))
Next

Dim file As EmailAttachment

// add attachments
If fileField.Text <> "" Then
file = New EmailAttachment
file.LoadFromFile(GetFolderItem(fileField.Text))
mail.Attachments.Append(file)
End If

// send the email
Socket1.Messages.Append(mail)
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 = ServerField.Text
Socket1.Port = 110

Socket1.UserName = UserNameField.Text
Socket1.Password = PasswordField.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 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.

Personal tools
Namespaces

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