|  | 
Chilkat  HOME  Android™  AutoIt  C  C#  C++  Chilkat2-Python  CkPython  Classic ASP  DataFlex  Delphi DLL  Go  Java  Node.js  Objective-C  PHP Extension  Perl  PowerBuilder  PowerShell  PureBasic  Ruby  SQL Server  Swift  Tcl  Unicode C  Unicode C++  VB.NET  VBScript  Visual Basic 6.0  Visual FoxPro  Xojo Plugin
| (Unicode C) Send Email With AttachmentsDemonstrates how to send an email with attachments. 
 #include <C_CkMailManW.h> #include <C_CkEmailW.h> void ChilkatSample(void) { HCkMailManW mailman; HCkEmailW email; BOOL success; const wchar_t *contentType; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // The mailman object is used for sending (SMTP) and receiving (POP3) email. mailman = CkMailManW_Create(); // Set the SMTP server. CkMailManW_putSmtpHost(mailman,L"smtp.my-tls-mail-server.com"); // Set the SMTP login/password (if required) CkMailManW_putSmtpUsername(mailman,L"MY_SMTP_USERNAME"); CkMailManW_putSmtpPassword(mailman,L"MY_SMTP_PASSWORD"); // Connect to SMTP port 465 using TLS. CkMailManW_putSmtpSsl(mailman,TRUE); CkMailManW_putSmtpPort(mailman,465); // Create a new email object email = CkEmailW_Create(); CkEmailW_putSubject(email,L"This is a test"); CkEmailW_putBody(email,L"This is a test"); CkEmailW_putFrom(email,L"Chilkat Support <support@chilkatsoft.com>"); success = CkEmailW_AddTo(email,L"Chilkat Admin",L"admin@chilkatsoft.com"); // To add more recipients, call AddTo, AddCC, or AddBcc once per recipient. // Add some attachments. // The AddFileAttachment method returns the value of the content-type it chose for the attachment. contentType = CkEmailW_addFileAttachment(email,L"qa_data/jpg/starfish.jpg"); if (CkEmailW_getLastMethodSuccess(email) != TRUE) { wprintf(L"%s\n",CkEmailW_lastErrorText(email)); CkMailManW_Dispose(mailman); CkEmailW_Dispose(email); return; } contentType = CkEmailW_addFileAttachment(email,L"qa_data/pdf/fishing.pdf"); if (CkEmailW_getLastMethodSuccess(email) != TRUE) { wprintf(L"%s\n",CkEmailW_lastErrorText(email)); CkMailManW_Dispose(mailman); CkEmailW_Dispose(email); return; } // Call SendEmail to connect to the SMTP server and send. // The connection (i.e. session) to the SMTP server remains // open so that subsequent SendEmail calls may use the // same connection. success = CkMailManW_SendEmail(mailman,email); if (success != TRUE) { wprintf(L"%s\n",CkMailManW_lastErrorText(mailman)); CkMailManW_Dispose(mailman); CkEmailW_Dispose(email); return; } success = CkMailManW_CloseSmtpConnection(mailman); if (success != TRUE) { wprintf(L"Connection to SMTP server not closed cleanly.\n"); } wprintf(L"Mail with attachments sent!\n"); CkMailManW_Dispose(mailman); CkEmailW_Dispose(email); } | ||||||
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.