Swift
Swift
SMTP Send Raw Command
Demonstrates how to send a raw command to the SMTP server after the connecting and authenticating.Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let mailman = CkoMailMan()!
mailman.smtpHost = "smtp.mail.us-west-2.awsapps.com"
mailman.smtpSsl = true
mailman.smtpPort = 465
success = mailman.smtpConnect()
if success == false {
print("\(mailman.lastErrorText!)")
return
}
mailman.smtpUsername = "john@example.com"
mailman.smtpPassword = "the_password"
success = mailman.smtpAuthenticate()
if success == false {
print("\(mailman.lastErrorText!)")
return
}
print("Authenticated!")
// Send the "EHLO" command again to get the multi-line response that includes the SMTP capabilities.
// The capabilities are the lines in the response that begin with "250-".
var responseStr: String? = mailman.smtpSendRawCommand(command: "EHLO client.example.com", charset: "utf-8", bEncodeBase64: false)
if mailman.lastMethodSuccess == false {
print("\(mailman.lastErrorText!)")
return
}
print("\(responseStr!)")
// A sample response:
// 250-smtp.us-west-2.mail.awsapps.com
// 250-8BITMIME
// 250-AUTH PLAIN LOGIN
// 250 Ok
}