AutoIt
AutoIt
Send Email With Attachments
See more SMTP Examples
Demonstrates how to send an email with attachments.Chilkat AutoIt Downloads
Local $bSuccess = False
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
; The mailman object is used for sending (SMTP) and receiving (POP3) email.
$oMailman = ObjCreate("Chilkat.MailMan")
; Set the SMTP server.
$oMailman.SmtpHost = "smtp.my-tls-mail-server.com"
; Set the SMTP login/password (if required)
$oMailman.SmtpUsername = "MY_SMTP_USERNAME"
$oMailman.SmtpPassword = "MY_SMTP_PASSWORD"
; Connect to SMTP port 465 using TLS.
$oMailman.SmtpSsl = True
$oMailman.SmtpPort = 465
; Create a new email object
$oEmail = ObjCreate("Chilkat.Email")
$oEmail.Subject = "This is a test"
$oEmail.Body = "This is a test"
$oEmail.From = "Chilkat Support <support@chilkatsoft.com>"
$bSuccess = $oEmail.AddTo("Chilkat Admin","admin@chilkatsoft.com")
; To add more recipients, call AddTo, AddCC, or AddBcc once per recipient.
; Add some attachments.
; The AddFileAttachment method returns the value of the content-type it chose for the attachment.
Local $sContentType = $oEmail.AddFileAttachment("qa_data/jpg/starfish.jpg")
If ($oEmail.LastMethodSuccess <> True) Then
ConsoleWrite($oEmail.LastErrorText & @CRLF)
Exit
EndIf
$sContentType = $oEmail.AddFileAttachment("qa_data/pdf/fishing.pdf")
If ($oEmail.LastMethodSuccess <> True) Then
ConsoleWrite($oEmail.LastErrorText & @CRLF)
Exit
EndIf
; Call SendEmail to connect to the SMTP server and send.
; The connection (i.e. session) to the SMTP server remains
; open so that subsequent SendEmail calls may use the
; same connection.
$bSuccess = $oMailman.SendEmail($oEmail)
If ($bSuccess <> True) Then
ConsoleWrite($oMailman.LastErrorText & @CRLF)
Exit
EndIf
$bSuccess = $oMailman.CloseSmtpConnection()
If ($bSuccess <> True) Then
ConsoleWrite("Connection to SMTP server not closed cleanly." & @CRLF)
EndIf
ConsoleWrite("Mail with attachments sent!" & @CRLF)