In this step by step guide, we share how to send email in C# using Aspose.Email for .NET. We’re sending email using Gmail SMTP server in this C# console application, but you can send email using any SMTP server in any type of .NET applications.
Steps to Send Email in C#
- Setup Aspose.Email for .NET from NuGet package manager
- Include the following namespaces: Aspose.Email, Aspose.Email.Clients, and Aspose.Email.Clients.Smtp
- Apply license using Aspose.Email.License class
- Create a new email message using MailMessage class
- Create instance of SmtpClient class
- Set Gmail SMTP client information to send email through
- Send email using Send method of SmtpClient class
Code to Send Email Using C#
Issue When you Send Email Using Gmail SMTP in C#
You might face an exception like “The SMTP server requires a secure connection or the client was not authenticated.”. This is because Gmail considers your application as less secure so may not allow to send email using their SMTP sever. To Fix Gmail SMTP issue allow access to less secure apps to send email.