SMTPSocket
From Xojo Documentation
This item was deprecated in version 2018r4. Please use SMTPSecureSocket as a replacement. |
Used to send email via the SMTP protocol. Use the EmailMessage class to create the email message to send.
Events | |||||||
|
Properties | ||||||||||||
|
Methods | |||||||||||
|
Notes
The POP3Socket and SMTPSocket classes are used together to form the basis of an email client. POP3 is the standard internet protocol for receiving messages and SMTP (Simple Mail Transfer Protocol) is the standard internet protocol for sending emails.
SMTPSocket supports the 'login' authentication type as well as 'plain.' This increases the authentication compatibility with some servers.
If you use a constructor in a subclass of SMTPSocket, you must call the Super class's constructor in your subclass's constructor. The subclass will not work unless this is done.
Gmail
Use SMTPSecureSocket to connect to Gmail.
Xojo Cloud
To access an SMTP server from web apps running on Xojo Cloud, you will first have to use the FirewallPort class to open the port used to connect to the SMTP Server:
XojoCloud.FirewallPort.Direction.Outgoing)
fwp.Open // This call is synchronous
If fwp.isOpen Then
// Do what you need to do
End If
Sample Code
The following code assumes an SMTPSocket named SendMailSocket, has been added to the window.
SendMailSocket.Port = 25 // Check your server for the property port # to use
// Create the actual email message
Dim mail As New EmailMessage
mail.FromAddress = "bill@yourdomain.com"
mail.Subject = "Test Email from Xojo"
mail.BodyPlainText = "Hello, World!"
mail.Headers.AppendHeader("X-Mailer", "Xojo SMTP Example") // Sample header
mail.AddRecipient("john@domain.com")
// Add the message to the SMTPSocket and send it
SendMailSocket.Messages.Append(mail)
SendMailSocket.SendMail
For complete examples that send and receive email, refer to these two projects that are included in the Xojo Examples:
- Examples/Communication/Internet/Email Example
- Examples/Communication/Internet/EmailSSLExample
See Also
EmailAttachment, EmailHeaders, EmailMessage, HTTPSecureSocket, HTTPSocket, POP3SecureSocket, POP3Socket, SMTPSecureSocket, SocketCore, TCPSocket classes.