-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Welcome to the Email.Net documentation.
Email.Net is developed to serve as an abstraction layer over the email sending mechanism used in our apps because in the life cycle of our app we intend to use and test different types of solutions, you may start with SMTP by using your own Gmail account in the devolvement phase, then you move to use a dedicated sending server like Socketlabs, Sendgrid ..., the idea is to have a well-developed abstraction to change the underlying implementation very easily without any changes in your code, and this what Email.Net try to solve.
Email.Net is composed of three blocks:
- EmailMessage: simply is the email message you want to send.
- EmailService: is the email service that you will be using to send the message.
- EDP: the Email Delivery Provider is the underlying mechanism used to send the email messages, which could be SMTP, MailKit, Socketlabs, etc.
the first thing we do is configure and set up the Email Service and Edps, then we compose the message and send it using the Email Service.
// get the email service
var emailService = EmailServiceFactory.Instance
.UseOptions(options =>
{
options.PauseSending = false;
options.DefaultFrom = new MailAddress("[email protected]");
options.DefaultEmailDeliveryProvider = SmtpEmailDeliveryProvider.Name;
})
.UseSmtp(options => options.UseGmailSmtp("[email protected]", "password"))
.Create();
// create the message
var message = EmailMessage.Compose()
.To("[email protected]")
.WithSubject("test email")
.WithPlainTextContent("this is a test email")
.WithHtmlContent("<p>this is a test email</p>")
.WithHighPriority()
.Build();
// send the message
var result = emailService.Send(message);
now we have a general idea of how Email.Net works, let dive into each component and learn how we can interact with it: