Skip to content
Youssef Sellami edited this page Dec 21, 2021 · 5 revisions

Welcome to the Email.Net documentation.

What is Email.Net?

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.

How it works?

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("from@email.net");
        options.DefaultEmailDeliveryProvider = SmtpEmailDeliveryProvider.Name;
    })
    .UseSmtp(options => options.UseGmailSmtp("your-email@gmail.com", "password"))
    .Create();

// create the message
var message = EmailMessage.Compose()
    .To("to@email.net")
    .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:

Clone this wiki locally