{{< figure align=center src=“images/Send-Outlook-Emails-in-C.jpg” alt=“Send Outlook Emails in C++">}}

In the previous article, you saw how to create MS Outlook emails—including MSG, EML, and EMLX—programmatically with C++. This post explains how to send Outlook emails from C++ applications. Emails can be generated at runtime or loaded from existing .msg, .emlx, or other files.

Send Emails with C++ Email Library - Free Download

As in the previous post, we’ll use Aspose.Email for C++ to send Outlook emails. Download the library from the Downloads page or install it via NuGet.

Send Outlook Emails using SMTP

Follow these steps to send an Outlook email with the SMTP client in Aspose.Email for C++:

  • Create an Outlook email or load it from a file with the MailMessage class.
  • Instantiate a SmtpClient object.
  • Set the host, username, password, and port.
  • Configure security options.
  • Call SmtpClient->Send() to deliver the message.

The sample below demonstrates sending an Outlook email with C++.

{{< gist aspose-com-gists d72533ad16b377f605e3af93f410cb26 “send-outlook-email.cpp” >}}

C++ Send Outlook Emails with Alternate View

You can add an alternate view to provide the same message in a different format, such as plain text for an HTML email. Use the method
MailMessage->get_AlternateViews()->Add(AlternateView::CreateAlternateViewFromString(u"text"))12.

The example below shows how to send an email with an alternate view in C++.

{{< gist aspose-com-gists d72533ad16b377f605e3af93f410cb26 “send-outlook-email-alternate-view.cpp” >}}

Send Bulk Emails using C++

When you need to send many emails at once, use the MailMessageCollection class to hold multiple messages. Steps:

  • Create or load messages with the MailMessage class.
  • Instantiate a MailMessageCollection object.
  • Add messages using MailMessageCollection->add().
  • Create a SmtpClient object.
  • Call SmtpClient->Send(MailMessageCollection) to send all messages.

The code sample below illustrates bulk sending with C++.

{{< gist aspose-com-gists d72533ad16b377f605e3af93f410cb26 “send-outlook-email-bulk.cpp” >}}

C++ Send Emails as TNEF

MS Outlook uses Transport Neutral Encapsulation Format (TNEF) for emails with RTF bodies. To send TNEF messages, enable it with SmtpClient->set_UseTnef(bool).

The following example sends an Outlook email as TNEF using C++.

{{< gist aspose-com-gists d72533ad16b377f605e3af93f410cb26 “send-outlook-email-tnef.cpp” >}}

Conclusion

This article showed how to send Outlook emails using C++. You also learned to send bulk messages, include alternate views, and transmit emails as TNEF. Explore more features of Aspose’s C++ email library in the documentation.

See Also