Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(C) Send Email with hotmail.com, live.com, or outlook.comSee more SMTP ExamplesSend 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
#include <C_CkMailMan.h> #include <C_CkJsonObject.h> #include <C_CkEmail.h> void ChilkatSample(void) { HCkMailMan mailman; HCkJsonObject json; BOOL success; HCkEmail email; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. mailman = CkMailMan_Create(); CkMailMan_putSmtpHost(mailman,"smtp.office365.com"); CkMailMan_putSmtpPort(mailman,587); CkMailMan_putStartTLS(mailman,TRUE); // This could be your hotmail.com, live.com, or outlook.com account. CkMailMan_putSmtpUsername(mailman,"yourName@live.com"); // Load the previously saved OAuth2 access token. json = CkJsonObject_Create(); success = CkJsonObject_LoadFile(json,"qa_data/tokens/hotmail.json"); if (success == FALSE) { printf("%s\n",CkJsonObject_lastErrorText(json)); CkMailMan_Dispose(mailman); CkJsonObject_Dispose(json); return; } CkMailMan_putOAuth2AccessToken(mailman,CkJsonObject_stringOf(json,"access_token")); email = CkEmail_Create(); // Note: If you send an email such as this, it can easily go to your Junk or Trash email folders. CkEmail_putSubject(email,"This is a test"); CkEmail_putBody(email,"This is a test"); // This could be your hotmail.com, live.com, or outlook.com account. CkEmail_putFrom(email,"My Hotmail Account <yourName@live.com>"); success = CkEmail_AddTo(email,"Joe Example","joe@example.com"); success = CkMailMan_OpenSmtpConnection(mailman); if (success != TRUE) { printf("%s\n",CkMailMan_lastErrorText(mailman)); printf("ConnectFailReason = %d\n",CkMailMan_getConnectFailReason(mailman)); CkMailMan_Dispose(mailman); CkJsonObject_Dispose(json); CkEmail_Dispose(email); return; } success = CkMailMan_SmtpAuthenticate(mailman); if (success != TRUE) { printf("%s\n",CkMailMan_lastErrorText(mailman)); CkMailMan_Dispose(mailman); CkJsonObject_Dispose(json); CkEmail_Dispose(email); return; } success = CkMailMan_SendEmail(mailman,email); if (success != TRUE) { printf("%s\n",CkMailMan_lastErrorText(mailman)); CkMailMan_Dispose(mailman); CkJsonObject_Dispose(json); CkEmail_Dispose(email); return; } CkMailMan_CloseSmtpConnection(mailman); printf("Email Sent.\n"); CkMailMan_Dispose(mailman); CkJsonObject_Dispose(json); CkEmail_Dispose(email); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.