In this tutorial, we will explore how to Send Email in C++. You will learn how to send mail using SMTP client on Gmail Server in C++ with simple API calls. You don’t need to install Microsoft Outlook or any other Email client to use the API in Windows and Linux platforms.
Steps to Send Email in C++
- Install Aspose.Email for C++ from NuGet package Manager
- Add reference to Aspose::Email namespace
- Connect to Gmail mailbox by using credentials in SmtpClient Class instance
- Load Email Message from disk using MailMessage Class instance
- By using Send exposed by SMTP client send email Message in C++
You can easily send email using SMTP Client connected to Gmail in C++ in few lines of code. In this example, we have shown how you can send EML format email using SMTP. You can also send MSG format email message as well and will require to use MsgLoadOption Class at line 42 of the example.
Code to Send Email in C++
Earlier, we learnt How to Send Email in C#. Whereas, this topic focuses on how you can send Email on Gmail Server using SMTP Client in C++. While using this example, you might get an exception like “The SMTP server requires a secure connection or the client was not authenticated”. Actually, Gmail suspects your application as less secure and forbids you to send email using their SMTP sever. In order to resolve the Gmail SMTP issue please visit topic, allow access to less secure apps to send email.