From Xojo Documentation

You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

Class (inherits from Object)

Used to hold attachments to an email.

ContentEncoding MIMEType
Data Name

LoadFromFile SaveToFile


The following example takes a path to a file and adds it as an email attachment. The path has been entered into the TextField named fileField.

Var mail As New EmailMessage
If fileField.Text <> "" Then
Var file As New EmailAttachment
file.LoadFromFile(New FolderItem(fileField.Text, FolderItem.PathModes.Native))
End If

This code accounts for some different file types:

Var mail As New EmailMessage
Var file As FolderItem = FolderItem.ShowOpenFileDialog("")
If file <> Nil And file.Exists Then
Var attachment As New EmailAttachment
attachment.Name = file.Name
If file.Name.Right(4) = ".pdf" Then
attachment.MIMEType = "application/pdf"
ElseIf file.Name.Right(4) = ".png" Then
attachment.MIMEType = "image/png"
ElseIf file.Name.Right(4) = ".jpg" Or attachment.Name.Right(5) = ".jpeg" Then
attachment.MIMEType = "image/jpeg"
// Else ' and so on with other extensions
End If
End If

See Also

EmailMessage, EmailHeaders, POP3Socket, POP3SecureSocket, SMTPSocket, SMTPSecureSocket, SocketCore, TCPSocket classes.