Skip to content
Araz Farhang Da edited this page Apr 15, 2019 · 1 revision

AIM (Aegis Implicit Mail) is a free and open-source .net library which aims to be a comprehensive mail client which supports all protocols for sending different types of mails in the easiest way for developers. AIM supports Implicit (SSL) and Explicit (TLS) for MIME and S/MIME emails with or without attachments.

If you have problem in sending emails to [port 465](C# - Send Email over SSL on 465 port) of gmail or other mail servers, AIM is what you are looking for!

[TOC]

Welcome to Aegis Implicit Mail(AIM)

If you are looking for information about Implicit mail servers please refer to [C# send email using implicit ssl]. You can also refer to [SSL VS TLS] to read more on SSL/TLS protocols

How to use AIM to send Ssl Mail?

Download Library

Our binary files are available as Nuget Packages https://www.nuget.org/packages/AIM

Or you can download from SourceForge

download_button by clicking on download button or getting source codes.

And then include it in your project!

Write the code!

If you want to have a sample SMTP mailing, you can write your program exactly like the way you write using System.Net.Mail

private void SendEmail()
{
    var mail = "[email protected]";
    var host = "smtp.gmail.com";
    var user = "yourUserName";
    var pass = "yourPassword";
    
    //Generate Message 
    var mymessage = new MimeMailMessage();
    mymessage.From = new MimeMailAddress(mail);
    mymessage.To.Add(mail);
    mymessage.Subject = "test";
    mymessage.Body = "body";
    
    //Create Smtp Client
    var mailer = new MimeMailer(host, 465);
    mailer.User= user;
    mailer.Password = pass;
    mailer.SslType = SslMode.Ssl;
    mailer.AuthenticationMode = AuthenticationType.Base64;
    
    //Set a delegate function for call back
    mailer.SendCompleted += compEvent;
    mailer.SendMailAsync(mymessage);
}

//Call back function
private void compEvent(object sender, AsyncCompletedEventArgs e)
{
    if (e.UserState!=null)
        Console.Out.WriteLine(e.UserState.ToString());
    
    Console.Out.WriteLine("is it canceled? " + e.Cancelled);

    if (e.Error != null)
            Console.Out.WriteLine("Error : " + e.Error.Message);
}

As you might be familiar with System.Net.Mail, we have four important objects in sending mails: Mail Message, Addresses, Attachment and sender. For each mail you need to generate mail message, set addresses and attachments and then send it using a smtp sender. AIM uses the same architecture. We have normal (mime) Mails and smime Mails that can be in a plain sender or Ssl Sender in addition Ssl Sender can be implicit and explicit.

In Conclusion you can [Send Mime Mails to Implicit Ssl Smtp Mail Servers](Send Mime Mails to Implicit Ssl Smtp Mail Servers),[Send SMIME Mails to Implicit Ssl Smtp Mail Servers](Send SMIME Mails to Implicit Ssl Smtp Mail Servers), [Send Mime Mails to Smtp Mail Servers](Send Mime Mails to Smtp Mail Servers), [Send SMIME mails to smtp mail servers](Send SMIME mails to smtp mail servers), [Send Mime Mails to Explicit Ssl Smtp Mail Servers](Send Mime Mails to Explicit Ssl Smtp Mail Servers) and [Send SMIME Mails to Explicit Ssl Smtp Mail Servers](Send SMIME Mails to Explicit Ssl Smtp Mail Servers) using same an exact same logic. Another alternative is to use our mail factory class which is able to send all mentioned mails

What is the underlying Architecture?

As mentioned, we will face with four concepts: Mail Messages, Mail Addresses, Attachments and Mail Senders

Mail Message

All mail messages in Aegis Implicit Mail are extending an abstract class called AbstractMailMessage which is an extended System.Net.Mail. If you want to send MIME messages (nor mal emails) you need to use MimeMailMessage and if you are about to send a smime (Signed/Encrypted) mail you need to use SmimeMailMessage.

MimeMailMessage is made to support our extended Mime Attachments and SmimeMailMessage is to enhance Mail messages with Cryptography functionalities

Mail Addresses

All Mail Addresses are Implementing IMailAddress. So we can cast them to each other and use generic classes. For the time being MimeMailAddress have nothing more than MailAddresses beside implementing IMailAddress Interface, while SmimeMailAddress Has Signing and Encryption certificates In order to be able to send Signed and encrypted Certificates to Mail Addresses

Attachments

All Attachments Classes should extend System.Net.Mail.Attachment.

MimeAttachment is implemented in order to add inline mail capabilities beside Attachment functionalities. In the other hand, MimeAttachment can have two types, inline and attached.

The most important thing that we need for Smime Attachment is to be able to sign and encrypt it. Therefore we need to have the data of attachment file (as byte array). In the other hand we don't need to have any specific object for the Smime attachments we use the .net Attachment class and in sender we just read it's content and will sign and encrypt it. Therefor, to send an smime mail you can use System.Net.Mail.Attachment

Mail Senders

All mail senders should implement an interface called IMailer. This interface is used to define mail generation and mail sending functions. Mail Senders are used to send Mime And Smime Messages with specified attachments and receivers to specified users You can use MimeMailer for sending mime messages and SmimeMailer for sending smime mails.

How to Identify Mail Server type?

AIM has support for ssl type detection, all you need to do is to have a MimeMailer object and then Call detect ssl type function. For more information please refer to our sample codes or [How To Detect Ssl Type](How To Detect Ssl Type)

How To Detect If a Server Support TLS?

In our test application you can find the sample codes to check for Explicit Ssl Smtp Server If you need more please have a look at [How To Detect Tls Support](How To Detect Tls Support)