Sample code for 30+ languages & platforms
Swift

Send Email using smtp-mail.outlook.com with Password Authentication

See more SMTP Examples

Demonstrates how to send an email using smtp-mail.outlook.com using password authentication.

Chilkat Swift Downloads

Swift

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.outlook.com"
    mailman.smtpPort = 587
    mailman.startTLS = true

    // Set the SMTP login/password
    mailman.smtpUsername = "OFFICE365_USERNAME"
    mailman.smtpPassword = "OFFICE365_PASSWORD"

    // Create a new email object
    let email = CkoEmail()!

    email.subject = "This is a test"
    email.body = "This is a test"
    email.from = "My Name <my_office365_email@outlook.com>"
    success = email.add(to: "Chilkat Admin", emailAddress: "admin@chilkatsoft.com")

    success = mailman.sendEmail(email: email)
    if success != true {
        print("\(mailman.lastErrorText!)")
        return
    }

    print("\(mailman.smtpSessionLog!)")

    success = mailman.closeSmtpConnection()
    if success != true {
        print("Connection to SMTP server not closed cleanly.")
    }

    print("Email Sent!")

}