Unicode C++
Unicode C++
Send an Email via SMTP
See more SMTP Examples
Demonstrates the Chilkat MailMan.SendEmail method, which sends a single Email object through the configured SMTP server. This example configures the SMTP connection, builds a message, and sends it.
Background: SMTP (Simple Mail Transfer Protocol) is the protocol for sending mail. The typical flow is: connect to the server, authenticate, then hand over the message with
MAIL FROM, RCPT TO, and DATA. SendEmail wraps all of that: you build an Email with subject, recipients, and body, and Chilkat renders it to MIME and delivers it. Modern submission commonly uses implicit TLS on port 465 (SmtpSsl = true).Chilkat Unicode C++ Downloads
#include <CkMailManW.h>
#include <CkEmailW.h>
void ChilkatSample(void)
{
bool success = false;
// Demonstrates the MailMan.SendEmail method, which sends a single Email object through the
// configured SMTP server.
CkMailManW mailman;
// Configure the SMTP server connection.
mailman.put_SmtpHost(L"smtp.example.com");
mailman.put_SmtpPort(465);
mailman.put_SmtpSsl(true);
mailman.put_SmtpUsername(L"user@example.com");
mailman.put_SmtpPassword(L"myPassword");
// Build the email to send.
CkEmailW email;
email.put_Subject(L"Test email from Chilkat");
email.put_From(L"alice@example.com");
email.AddTo(L"Bob",L"bob@example.com");
email.put_Body(L"Hello, this is a test message.");
// Send the email.
success = mailman.SendEmail(email);
if (success == false) {
wprintf(L"%s\n",mailman.lastErrorText());
return;
}
wprintf(L"Email sent.\n");
// Note: Explicitly connecting/authenticating is optional. Chilkat MailMan automatically
// connects and authenticates -- using the property settings above -- whenever a server
// operation requires it. Calling the explicit connect/authenticate methods can still be
// helpful to determine whether a failure occurs while connecting or while authenticating.
}