Xbase++
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oMailman
LOCAL oJson
LOCAL oEmail
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oMailman := CreateObject("Chilkat.MailMan")
oMailman:SmtpHost := "smtp.office365.com"
oMailman:SmtpPort := 587
oMailman:StartTLS := 1
// This could be your hotmail.com, live.com, or outlook.com account.
oMailman:SmtpUsername := "yourName@live.com"
// Load the previously saved OAuth2 access token.
oJson := CreateObject("Chilkat.JsonObject")
nSuccess := oJson:LoadFile("qa_data/tokens/hotmail.json")
IF (nSuccess == 0)
? oJson:LastErrorText
oMailman:destroy()
oJson:destroy()
RETURN
ENDIF
oMailman:OAuth2AccessToken := oJson:StringOf("access_token")
oEmail := CreateObject("Chilkat.Email")
// Note: If you send an email such as this, it can easily go to your Junk or Trash email folders.
oEmail:Subject := "This is a test"
oEmail:Body := "This is a test"
// This could be your hotmail.com, live.com, or outlook.com account.
oEmail:From := "My Hotmail Account <yourName@live.com>"
nSuccess := oEmail:AddTo("Joe Example", "joe@example.com")
nSuccess := oMailman:OpenSmtpConnection()
IF (nSuccess != 1)
? oMailman:LastErrorText
? "ConnectFailReason = " + Str(oMailman:ConnectFailReason)
oMailman:destroy()
oJson:destroy()
oEmail:destroy()
RETURN
ENDIF
nSuccess := oMailman:SmtpAuthenticate()
IF (nSuccess != 1)
? oMailman:LastErrorText
oMailman:destroy()
oJson:destroy()
oEmail:destroy()
RETURN
ENDIF
nSuccess := oMailman:SendEmail(oEmail)
IF (nSuccess != 1)
? oMailman:LastErrorText
oMailman:destroy()
oJson:destroy()
oEmail:destroy()
RETURN
ENDIF
oMailman:CloseSmtpConnection()
? "Email Sent."
oMailman:destroy()
oJson:destroy()
oEmail:destroy()