Sample code for 30+ languages & platforms
PureBasic

Amazon SES SMTP: Send email over implicit TLS on port 465

See more Amazon SES Examples

Connect to the regional SES SMTP endpoint with TLS from the start of the connection. Load the SMTP username and password from protected application configuration. SES SMTP passwords are Region-specific and differ from AWS secret access keys used to sign API requests. Replace the From address with a verified sender. The example delivers to the SES mailbox simulator.

TLS connections to SES SMTP · Obtain SMTP credentials

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkEmail.pb"
IncludeFile "CkMailMan.pb"

Procedure ChilkatExample()

    success.i = 0

    ;  Assumes Chilkat is unlocked. See Global Unlock Sample.

    success = 0

    mail.i = CkMailMan::ckCreate()
    If mail.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ;  Use the SMTP endpoint and SMTP credentials issued for the same AWS Region.
    CkMailMan::setCkSmtpHost(mail, "email-smtp.us-west-2.amazonaws.com")
    CkMailMan::setCkSmtpPort(mail, 465)
    CkMailMan::setCkSmtpSsl(mail, 1)
    CkMailMan::setCkRequireSslCertVerify(mail, 1)
    CkMailMan::setCkSmtpUsername(mail, "SES_SMTP_USERNAME")
    CkMailMan::setCkSmtpPassword(mail, "SES_SMTP_PASSWORD")

    email.i = CkEmail::ckCreate()
    If email.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkEmail::setCkFrom(email, "sender+reports@example.com")
    CkEmail::setCkSubject(email, "SES SMTP connection test")
    CkEmail::setCkBody(email, "This message was submitted over implicit TLS on port 465.")
    success = CkEmail::ckAddTo(email,"SES mailbox simulator","success@simulator.amazonses.com")
    If success <> 1
        Debug CkEmail::ckLastErrorText(email)
        CkMailMan::ckDispose(mail)
        CkEmail::ckDispose(email)
        ProcedureReturn
    EndIf

    success = CkMailMan::ckSendEmail(mail,email)
    If success <> 1
        Debug CkMailMan::ckLastErrorText(mail)
        CkMailMan::ckDispose(mail)
        CkEmail::ckDispose(email)
        ProcedureReturn
    EndIf

    Debug "SES accepted the message over SMTP."
    success = CkMailMan::ckCloseSmtpConnection(mail)
    If success <> 1
        ;  The server already accepted the message. Retrying here could send a duplicate.
        Debug "The SMTP connection did not close cleanly."
    EndIf



    CkMailMan::ckDispose(mail)
    CkEmail::ckDispose(email)


    ProcedureReturn
EndProcedure