DataFlex
DataFlex
Send an Email via SMTP
See more SMTP Examples
Demonstrates the Chilkat MailMan.SendEmail method, which sends a single Email object through the configured SMTP server. This example configures the SMTP connection, builds a message, and sends it.
Background: SMTP (Simple Mail Transfer Protocol) is the protocol for sending mail. The typical flow is: connect to the server, authenticate, then hand over the message with
MAIL FROM, RCPT TO, and DATA. SendEmail wraps all of that: you build an Email with subject, recipients, and body, and Chilkat renders it to MIME and delivers it. Modern submission commonly uses implicit TLS on port 465 (SmtpSsl = true).Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoMailman
Variant vEmail
Handle hoEmail
String sTemp1
Move False To iSuccess
// Demonstrates the MailMan.SendEmail method, which sends a single Email object through the
// configured SMTP server.
Get Create (RefClass(cComChilkatMailMan)) To hoMailman
If (Not(IsComObjectCreated(hoMailman))) Begin
Send CreateComObject of hoMailman
End
// Configure the SMTP server connection.
Set ComSmtpHost Of hoMailman To "smtp.example.com"
Set ComSmtpPort Of hoMailman To 465
Set ComSmtpSsl Of hoMailman To True
Set ComSmtpUsername Of hoMailman To "user@example.com"
Set ComSmtpPassword Of hoMailman To "myPassword"
// Build the email to send.
Get Create (RefClass(cComChilkatEmail)) To hoEmail
If (Not(IsComObjectCreated(hoEmail))) Begin
Send CreateComObject of hoEmail
End
Set ComSubject Of hoEmail To "Test email from Chilkat"
Set ComFrom Of hoEmail To "alice@example.com"
Get ComAddTo Of hoEmail "Bob" "bob@example.com" To iSuccess
Set ComBody Of hoEmail To "Hello, this is a test message."
// Send the email.
Get pvComObject of hoEmail to vEmail
Get ComSendEmail Of hoMailman vEmail To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoMailman To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "Email sent."
// Note: Explicitly connecting/authenticating is optional. Chilkat MailMan automatically
// connects and authenticates -- using the property settings above -- whenever a server
// operation requires it. Calling the explicit connect/authenticate methods can still be
// helpful to determine whether a failure occurs while connecting or while authenticating.
End_Procedure