Send Outlook Emails in C++

In the previous article, you have seen how to create MS Outlook emails including MSG, EML, and EMLX programmatically using C++. In this post, you’ll learn how to send Outlook emails from within C++ applications. The emails can be created on the runtime or loaded from already saved email files such as .msg, .emlx, or etc.

Send Emails with C++ Email Library - Free Download

Likewise the previous post, we’ll use Aspose.Email for C++ to send the Outlook emails. You can download the library files from the Downloads section or install it using NuGet.

Send Outlook Emails using C++

The following are the steps to send an Outlook email with SMTP client using Aspose.Email for C++.

  • Create an Outlook email or load it from a file using the MailMessage class.
  • Create an object of SmtpClient.
  • Set host, username, password, and port number.
  • Set security options.
  • Send email using SmtpClient->Send() method.

The following code sample shows how to send an Outlook email using C++.

C++ Send Outlook Emails with Alternate View

You may also specify an alternate view of the email to create a copy of the message in a different format. For instance, if your message is in HTML format, you can create an alternate view having a plain text. In order to create an alternate view, you can use MailMessage->get_AlternateViews()->Add(AlternateView::CreateAlternateViewFromString(u"text")) method.

The following code sample shows how to send an email with an alternate view using C++.

Send Bulk Emails using C++

There might be the case when you need to send a bulk of emails at a time. For such cases, Aspose.Email for C++ provides MailMessageCollection class to encapsulate multiple email messages. The following are steps to send the bulk of emails.

  • Create or load email messages using the MailMessage class.
  • Create an object of the MailMessageCollection class.
  • Add email messages to the collection using MailMessageCollection->add() method.
  • Create an object of the SmtpClient class.
  • Send bulk emails using SmtpClient->Send(MailMessageCollection) method.

The following code sample shows how to send the bulk of emails using C++.

C++ Send Emails as TNEF

MS Outlook uses Transport Neutral Encapsulation Format (TNEF) to send the emails having RTF bodies. In this case, the formatting is extracted from the email and it is encoded as TNEF. At the receiving end, if the client supports TNEF, it assembles the plain text and the TNEF attachment to create the RTF email. Otherwise, the email is displayed as plain text. In order to send emails as TNEF, you can use SmtpClient->set_UseTnef(bool) method.

The following code sample shows how to send an Outlook email as TNEF using C++.

Conclusion

In this post, you have seen how to send Outlook emails using C++. In addition, you have come to know how to send bulk emails, send emails with an alternate view, or send emails as TNEF within C++ applications. You can explore more about Aspose’s C++ email library using the documentation.

See Also