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
(Unicode 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_CkMailManW.h> #include <C_CkJsonObjectW.h> #include <C_CkEmailW.h> void ChilkatSample(void) { HCkMailManW mailman; HCkJsonObjectW json; BOOL success; HCkEmailW email; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. mailman = CkMailManW_Create(); CkMailManW_putSmtpHost(mailman,L"smtp.office365.com"); CkMailManW_putSmtpPort(mailman,587); CkMailManW_putStartTLS(mailman,TRUE); // This could be your hotmail.com, live.com, or outlook.com account. CkMailManW_putSmtpUsername(mailman,L"yourName@live.com"); // Load the previously saved OAuth2 access token. json = CkJsonObjectW_Create(); success = CkJsonObjectW_LoadFile(json,L"qa_data/tokens/hotmail.json"); if (success == FALSE) { wprintf(L"%s\n",CkJsonObjectW_lastErrorText(json)); CkMailManW_Dispose(mailman); CkJsonObjectW_Dispose(json); return; } CkMailManW_putOAuth2AccessToken(mailman,CkJsonObjectW_stringOf(json,L"access_token")); email = CkEmailW_Create(); // Note: If you send an email such as this, it can easily go to your Junk or Trash email folders. CkEmailW_putSubject(email,L"This is a test"); CkEmailW_putBody(email,L"This is a test"); // This could be your hotmail.com, live.com, or outlook.com account. CkEmailW_putFrom(email,L"My Hotmail Account <yourName@live.com>"); success = CkEmailW_AddTo(email,L"Joe Example",L"joe@example.com"); success = CkMailManW_OpenSmtpConnection(mailman); if (success != TRUE) { wprintf(L"%s\n",CkMailManW_lastErrorText(mailman)); wprintf(L"ConnectFailReason = %d\n",CkMailManW_getConnectFailReason(mailman)); CkMailManW_Dispose(mailman); CkJsonObjectW_Dispose(json); CkEmailW_Dispose(email); return; } success = CkMailManW_SmtpAuthenticate(mailman); if (success != TRUE) { wprintf(L"%s\n",CkMailManW_lastErrorText(mailman)); CkMailManW_Dispose(mailman); CkJsonObjectW_Dispose(json); CkEmailW_Dispose(email); return; } success = CkMailManW_SendEmail(mailman,email); if (success != TRUE) { wprintf(L"%s\n",CkMailManW_lastErrorText(mailman)); CkMailManW_Dispose(mailman); CkJsonObjectW_Dispose(json); CkEmailW_Dispose(email); return; } CkMailManW_CloseSmtpConnection(mailman); wprintf(L"Email Sent.\n"); CkMailManW_Dispose(mailman); CkJsonObjectW_Dispose(json); CkEmailW_Dispose(email); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.