Sample code for 30+ languages & platforms
Tcl

Send Email with hotmail.com, live.com, or outlook.com

See more SMTP Examples

Send email using your Microsoft hotmail.com, live.com, or outlook.com account via the smtp.office365.com SMTP server.

See the Guide for Creating an Application to Send Email from Hotmail.com, Live.com, or Outlook.com

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

set mailman [new_CkMailMan]

CkMailMan_put_SmtpHost $mailman "smtp.office365.com"
CkMailMan_put_SmtpPort $mailman 587
CkMailMan_put_StartTLS $mailman 1

# This could be your hotmail.com, live.com, or outlook.com account.
CkMailMan_put_SmtpUsername $mailman "yourName@live.com"

# Load the previously saved OAuth2 access token.
set json [new_CkJsonObject]

set success [CkJsonObject_LoadFile $json "qa_data/tokens/hotmail.json"]
if {$success == 0} then {
    puts [CkJsonObject_lastErrorText $json]
    delete_CkMailMan $mailman
    delete_CkJsonObject $json
    exit
}

CkMailMan_put_OAuth2AccessToken $mailman [CkJsonObject_stringOf $json "access_token"]

set email [new_CkEmail]

# Note: If you send an email such as this, it can easily go to your Junk or Trash email folders.
CkEmail_put_Subject $email "This is a test"
CkEmail_put_Body $email "This is a test"
# This could be your hotmail.com, live.com, or outlook.com account.
CkEmail_put_From $email "My Hotmail Account <yourName@live.com>"
set success [CkEmail_AddTo $email "Joe Example" "joe@example.com"]

set success [CkMailMan_OpenSmtpConnection $mailman]
if {$success != 1} then {
    puts [CkMailMan_lastErrorText $mailman]
    puts "ConnectFailReason = [CkMailMan_get_ConnectFailReason $mailman]"
    delete_CkMailMan $mailman
    delete_CkJsonObject $json
    delete_CkEmail $email
    exit
}

set success [CkMailMan_SmtpAuthenticate $mailman]
if {$success != 1} then {
    puts [CkMailMan_lastErrorText $mailman]
    delete_CkMailMan $mailman
    delete_CkJsonObject $json
    delete_CkEmail $email
    exit
}

set success [CkMailMan_SendEmail $mailman $email]
if {$success != 1} then {
    puts [CkMailMan_lastErrorText $mailman]
    delete_CkMailMan $mailman
    delete_CkJsonObject $json
    delete_CkEmail $email
    exit
}

CkMailMan_CloseSmtpConnection $mailman

puts "Email Sent."

delete_CkMailMan $mailman
delete_CkJsonObject $json
delete_CkEmail $email