PureBasic
PureBasic
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 PureBasic Downloads
IncludeFile "CkJsonObject.pb"
IncludeFile "CkEmail.pb"
IncludeFile "CkMailMan.pb"
Procedure ChilkatExample()
success.i = 0
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
mailman.i = CkMailMan::ckCreate()
If mailman.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkMailMan::setCkSmtpHost(mailman, "smtp.office365.com")
CkMailMan::setCkSmtpPort(mailman, 587)
CkMailMan::setCkStartTLS(mailman, 1)
; This could be your hotmail.com, live.com, or outlook.com account.
CkMailMan::setCkSmtpUsername(mailman, "yourName@live.com")
; Load the previously saved OAuth2 access token.
json.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkJsonObject::ckLoadFile(json,"qa_data/tokens/hotmail.json")
If success = 0
Debug CkJsonObject::ckLastErrorText(json)
CkMailMan::ckDispose(mailman)
CkJsonObject::ckDispose(json)
ProcedureReturn
EndIf
CkMailMan::setCkOAuth2AccessToken(mailman, CkJsonObject::ckStringOf(json,"access_token"))
email.i = CkEmail::ckCreate()
If email.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; Note: If you send an email such as this, it can easily go to your Junk or Trash email folders.
CkEmail::setCkSubject(email, "This is a test")
CkEmail::setCkBody(email, "This is a test")
; This could be your hotmail.com, live.com, or outlook.com account.
CkEmail::setCkFrom(email, "My Hotmail Account <yourName@live.com>")
success = CkEmail::ckAddTo(email,"Joe Example","joe@example.com")
success = CkMailMan::ckOpenSmtpConnection(mailman)
If success <> 1
Debug CkMailMan::ckLastErrorText(mailman)
Debug "ConnectFailReason = " + Str(CkMailMan::ckConnectFailReason(mailman))
CkMailMan::ckDispose(mailman)
CkJsonObject::ckDispose(json)
CkEmail::ckDispose(email)
ProcedureReturn
EndIf
success = CkMailMan::ckSmtpAuthenticate(mailman)
If success <> 1
Debug CkMailMan::ckLastErrorText(mailman)
CkMailMan::ckDispose(mailman)
CkJsonObject::ckDispose(json)
CkEmail::ckDispose(email)
ProcedureReturn
EndIf
success = CkMailMan::ckSendEmail(mailman,email)
If success <> 1
Debug CkMailMan::ckLastErrorText(mailman)
CkMailMan::ckDispose(mailman)
CkJsonObject::ckDispose(json)
CkEmail::ckDispose(email)
ProcedureReturn
EndIf
CkMailMan::ckCloseSmtpConnection(mailman)
Debug "Email Sent."
CkMailMan::ckDispose(mailman)
CkJsonObject::ckDispose(json)
CkEmail::ckDispose(email)
ProcedureReturn
EndProcedure