MailMessage
Throughout the course of this article, weâll often be using MailMessage
class. Itâs a part of System.Net.Mail
namespace and is used to create email messages that are then sent to an SMTP server. The delivery is then taken care of by the SmtpClient
class.
For the complete set of parameters of this class, please refer to Microsoftâs documentation.
Sending emails in C# with SMTP
This one is fairly easy and quick to set up as SMTP (Simple Mail Transfer Protocol) is the most common communication standard used in email transmission. In the example below, weâll show how to send a very simple email with the following details:
To: elizabeth@westminster.co.uk
From: piotr@mailtrap.io
Title: Good morning, Elizabeth
Body: Elizabeth, Long time no talk. Would you be up for lunch in Soho on Monday? Iâm paying.
In order to send such an email, weâll use the aforementioned MailMessage
class from .NET API.