Aoxe.SmtpClient.Provider 2024.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Aoxe.SmtpClient.Provider --version 2024.1.1                
NuGet\Install-Package Aoxe.SmtpClient.Provider -Version 2024.1.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Aoxe.SmtpClient.Provider" Version="2024.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Aoxe.SmtpClient.Provider --version 2024.1.1                
#r "nuget: Aoxe.SmtpClient.Provider, 2024.1.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Aoxe.SmtpClient.Provider as a Cake Addin
#addin nuget:?package=Aoxe.SmtpClient.Provider&version=2024.1.1

// Install Aoxe.SmtpClient.Provider as a Cake Tool
#tool nuget:?package=Aoxe.SmtpClient.Provider&version=2024.1.1                

Aoxe.Email

English | 简体中文

Email, as a messenger of information in the digital age, has transcended the limitations of time and space and, with its unique and far-reaching influence, has been quietly integrated into the veins of civilisation.

For cloud neutrality, we may need a tool that can help us manage our email more efficiently. Aoxe.Email is such a tool. It is a powerful email client that can help you send emails, and avoids being tied to the cloud.


1. What is Aoxe.Email?

The Aoxe.Email has the following implementations for sending emails:

1.1. Aoxe.Aws.SimpleEmail

This is the first release of version 2 of the Amazon SES API. You can use this API to configure your Amazon SES account, and to send email. This API extends the functionality that exists in the previous version of the Amazon SES API.

1.2. Aoxe.Azure.Email

This client library enables working with the Microsoft Azure Communication Email service.

1.3. Aoxe.MailKit

MailKit is an Open Source cross-platform .NET mail-client library that is based on MimeKit and optimized for mobile devices.

1.4. Aoxe.SmtpClient

Use System.Net.Mail.SmtpClient.

2. How to use Aoxe.Email?

Install the package

PM> Install-Package Aoxe.Aws.SimpleEmail
PM> Install-Package Aoxe.Azure.Email
PM> Install-Package Aoxe.MailKit
PM> Install-Package Aoxe.SmtpClient

Register the email provider. All the implements has the same abstractions so we can easily switch between them.

// Please replace the host and port with your own, you can use user name and password for the authentication and so on
serviceCollection.AddMailKit("your host", 25);
serviceCollection.AddSmtpClient("your host", 25);
// The aws and azure email provider has different Add method to match their own constructors
serviceCollection.AddAwsSimpleEmail("awsAccessKeyId", "awsSecretAccessKey");
serviceCollection.AddAzureEmail("connectionString");

Inject the email provider by reference Aoxe.Email.Abstractions.

PM> Install-Package Aoxe.Email.Abstractions
public class EmailService
{
    private readonly IEmailProvider _emailProvider;

    public EmailService(IEmailProvider emailProvider)
    {
        _emailProvider = emailProvider;
    }

    public async Task SendEmailAsync(string subject, string text, string fromAddress, string toAddress)
    {
        var email = new Abstractions.Models.Email();
        email
            .Subject(subject)
            .TextBody(email)
            .EmailFrom(fromAddress)
            .EmailTo(toAddress);
        // You can send the email with extension method
        await email.SendByAsync(_emailProvider);
        // Or you can send the email with the provider
        await _emailProvider.SendAsync(email);
    }
}

3. About Aoxe.Email.Abstractions.Models.Email

The Aoxe.Email.Abstractions.Models.Email class is a comprehensive representation of an email message. Here's a brief overview of its structure and functionality:

  1. It uses the primary constructor to optionally set an ID.
  2. It has properties for various email components like From, Sender, ReplyTo, Recipients, Content, and Attachments.
  3. The class implements a fluent interface pattern, allowing method chaining for easy email composition.

Key features:

  1. Attachment handling (single and multiple)
  2. Setting email subject, text body, and HTML body
  3. Managing email addresses (From, To, Cc, Bcc, ReplyTo, Sender)
  4. Each method returns this, enabling method chaining.

You can new an Email like this:

var (fileName, fileBytes) = await FileHelper.LoadFileBytesAsync("AttachmentTestFile.txt");
_ = new Models.Email
{
    From = new EmailAddress("from@fake.com", "from"),
    Sender = new EmailAddress("sender@fake.com", "sender"),
    Recipients = new EmailRecipients
    {
        To = [new EmailAddress("to@fake.com", "to")],
        Cc = [new EmailAddress("cc@fake.com", "cc")],
        Bcc = [new EmailAddress("bcc@fake.com", "bcc")],
    },
    ReplyTo = [new EmailAddress("replyto@fake.com", "replyTo")],
    Content = new EmailContent
    {
        Subject = "Subject",
        TextBody = "TextBody",
        HtmlBody = "HtmlBody",
    },
    Attachments = [new EmailAttachment(fileName, fileBytes)]
};

Also you can use a fluent style:

var email = new Models.Email();
email
    .Subject("subject")
    .TextBody("textBody")
    .HtmlBody("htmlBody")
    .EmailFrom("address", "name")
    .EmailTo("address0", "name0")
    .EmailTo([new EmailAddress("address1", "name1"), new EmailAddress("address2", "name2")])
    .EmailCc("address0", "name0")
    .EmailCc([new EmailAddress("address1", "name1"), new EmailAddress("address2", "name2")])
    .EmailBcc("address0", "name0")
    .EmailBcc(
        [new EmailAddress("address1", "name1"), new EmailAddress("address2", "name2")]
    )
    .EmailReplyTo("address0", "name0")
    .EmailReplyTo(
        [new EmailAddress("address1", "name1"), new EmailAddress("address2", "name2")]
    )
    .EmailSender("address", "name");
var (fileName, fileBytes) = await FileHelper.LoadFileBytesAsync("AttachmentTestFile.txt");
email
    .Attach(fileName, fileBytes)
    .Attach([new(fileName, fileBytes), new(fileName, fileBytes)]);

In each implement package the Aoxe.Email.Abstractions.Models.Email has its extension methord to convert it into the specify email model which the email client want:

// Return Amazon.SimpleEmailV2.Model.SendEmailRequest for IAmazonSimpleEmailServiceV2
email.ToSendEmailRequest();
// Return Azure.Communication.Email.EmailMessage for Azure.Communication.Email.EmailClient
email.ToEmailMessage();
// Return MimeKit.MimeMessage for IMailTransport
email.ToMimeMessage();
// Return System.Net.Mail.MailMessage for System.Net.Mail.SmtpClient
email.ToMailMessage();

This will help you to use the email client with more customization, here is the example in Aoxe.MailKit:

var email = new Models.Email();
var mimeMessage = email.ToMimeMessage();
// Just a demo so use memory stream.
var smtpClient = new SmtpClient(new ProtocolLogger(new MemoryStream()));
await smtpClient.ConnectAsync(host, port);
// If need authenticate
await smtpClient.AuthenticateAsync(userName, password);
await _mailTransport.SendAsync(mimeMessage, cancellationToken);

Thank`s for JetBrains for the great support in providing assistance and user-friendly environment for my open source projects.

JetBrains

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Aoxe.SmtpClient.Provider:

Package Downloads
Aoxe.SmtpClient

The aoxe email provider implement by SmtpClient.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2025.1.0 128 11/14/2024
2024.1.1 99 11/5/2024
2024.1.0 121 10/12/2024