DataFlex
DataFlex
Send Pre-Built MIME via SMTP
See more SMTP Examples
Demonstrates the Chilkat MailMan.SendMime method, which sends an email from caller-supplied MIME text. The arguments are the from address, the recipient list (the SMTP envelope recipients), and the MIME source. This example builds an email, gets its MIME, and sends that MIME.
Important: When sending caller-supplied MIME, ensure the Message-ID header is unique for each message. Sending MIME whose Message-ID was previously used can cause the message to be silently discarded as a duplicate by mail servers — see chilkatsoft.com/email_duplicate_message_id.asp.
Background: Sometimes you already have a complete message as raw MIME — loaded from a
.eml file, generated elsewhere, or archived earlier — and just need to deliver it as-is. SendMime hands that MIME straight to the SMTP server. Note the distinction between the envelope recipients (the second argument, who the server actually delivers to) and the To/Cc headers inside the MIME (what the recipient sees) — they can legitimately differ, which is how Bcc works.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoMailman
Handle hoEmail
String sMimeText
String sTemp1
Move False To iSuccess
// Demonstrates the MailMan.SendMime method, which sends an email from caller-supplied MIME
// text. The arguments are the from address, the recipient list (the SMTP envelope
// recipients), and the MIME source.
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"
// Obtain the MIME to send. Here we build an Email and get its MIME, but the MIME could
// come from any source.
Get Create (RefClass(cComChilkatEmail)) To hoEmail
If (Not(IsComObjectCreated(hoEmail))) Begin
Send CreateComObject of hoEmail
End
Set ComSubject Of hoEmail To "Test email"
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 message was sent as MIME."
Get ComGetMime Of hoEmail To sMimeText
// IMPORTANT: When sending caller-supplied MIME, make sure the Message-ID header is unique
// for each message. Sending MIME that contains a Message-ID that was previously sent can
// cause the message to be silently discarded as a duplicate by mail servers. For details,
// see: https://www.chilkatsoft.com/email_duplicate_message_id.asp
// Send the MIME to the envelope recipient(s).
Get ComSendMime Of hoMailman "alice@example.com" "bob@example.com" sMimeText To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoMailman To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "MIME 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