Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Mailman
oleobject loo_Json
oleobject loo_Email

li_Success = 0

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

loo_Mailman = create oleobject
li_rc = loo_Mailman.ConnectToNewObject("Chilkat.MailMan")
if li_rc < 0 then
    destroy loo_Mailman
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_Mailman.SmtpHost = "smtp.office365.com"
loo_Mailman.SmtpPort = 587
loo_Mailman.StartTLS = 1

// This could be your hotmail.com, live.com, or outlook.com account.
loo_Mailman.SmtpUsername = "yourName@live.com"

// Load the previously saved OAuth2 access token.
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

li_Success = loo_Json.LoadFile("qa_data/tokens/hotmail.json")
if li_Success = 0 then
    Write-Debug loo_Json.LastErrorText
    destroy loo_Mailman
    destroy loo_Json
    return
end if

loo_Mailman.OAuth2AccessToken = loo_Json.StringOf("access_token")

loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")

// Note: If you send an email such as this, it can easily go to your Junk or Trash email folders.
loo_Email.Subject = "This is a test"
loo_Email.Body = "This is a test"
// This could be your hotmail.com, live.com, or outlook.com account.
loo_Email.From = "My Hotmail Account <yourName@live.com>"
li_Success = loo_Email.AddTo("Joe Example","joe@example.com")

li_Success = loo_Mailman.OpenSmtpConnection()
if li_Success <> 1 then
    Write-Debug loo_Mailman.LastErrorText
    Write-Debug "ConnectFailReason = " + string(loo_Mailman.ConnectFailReason)
    destroy loo_Mailman
    destroy loo_Json
    destroy loo_Email
    return
end if

li_Success = loo_Mailman.SmtpAuthenticate()
if li_Success <> 1 then
    Write-Debug loo_Mailman.LastErrorText
    destroy loo_Mailman
    destroy loo_Json
    destroy loo_Email
    return
end if

li_Success = loo_Mailman.SendEmail(loo_Email)
if li_Success <> 1 then
    Write-Debug loo_Mailman.LastErrorText
    destroy loo_Mailman
    destroy loo_Json
    destroy loo_Email
    return
end if

loo_Mailman.CloseSmtpConnection()

Write-Debug "Email Sent."


destroy loo_Mailman
destroy loo_Json
destroy loo_Email