Giter VIP home page Giter VIP logo

aim's Introduction

Build Status

Aegis Implicit Mail (AIM)

Aegis Implicit Mail is a free and open source library which is designed to provide fast and developer friendly API to send emails using SMTP ports.

Why AIM

Sadly, Microsoft.Net.Mail Ssl Mails does not support Implicit Ssl Mail and it is still used by many servers, including port 465 of Gmail here AIM comes to make a readable and fast alternative to send your smtp mails.

Download

Binaries are available in the form of NuGet package

Getting the Code

To get a local copy of the current code, clone it using git:

$ git clone https://github.com/nilnull/AIM.git

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:

  1. Mail Message
  2. Addresses
  3. Attachment
  4. sender

For each mail you need to generate mail message,

  1. Set addresses
  2. Add attachments
  3. 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.

More information can be found at our wiki

Features

  • Support for both of S-MIME and Mime Messages
  • Easy to use and well designed, easy to migrate from System.Net.Mail
  • Support for Signed and/or encrypted mail
  • Supports Ssl Type detection (Detects if Mail server is using Implicit (SSL) or Explicit (TLS) smtp)
  • Support Base64, PlainText and default credential Authentication
  • Asynchronous Mail Sending
  • Support None Ssl Mails
  • Support Inline and Attached Attachments.
  • Signed and Encrypted attachments
  • Fast and reliable
  • Made by developers for developers
  • Test Connection Settings
  • Auto Detection of Ssl Type
  • Support Office 365
  • Support display name

Archive

Please check our archive here

Development Team

AIM is delivered by NilNull from PKI.Tools with special thanks to those who help us :

  • Eugene Jenihov
  • Dénes Gál-Szász
  • galdenny

aim's People

Contributors

araztln avatar brightsoul avatar carlosbet avatar davidezanella avatar eugene-zen avatar galdenny avatar mwidev avatar nilnull avatar psikola avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

aim's Issues

SmtpSocketClient NullReferenceException on TestConnection() method

TestConnection() method raises NullReferenceException when called without internet connection available.

Exception : {"Object reference not set to an instance of an object."} | System.NullReferenceException
StackTrace : " at AegisImplicitMail.SmtpSocketClient.QuiteConnection(String& response, Int32& code)\r\n at AegisImplicitMail.SmtpSocketClient.TestConnection()\r\n "
InnerException: null

Delemiter when using multiple to/cc/bcc recipients

Hi,
I had problems when sending mails to multiple recipients using some SMTP servers. After comparing the headers produced by AIM and Thunderbird I recognized, that Thunderbird uses "," as delemiter between multiple addresses and AIM using ";". According to rfc6068 the ","seems to be the correct way. After changing the 3 occurences in the SendMail() function it worked fine with all my test SMPT providers. Maybe you can double check if "," realy is correct and if so update your code base.

best regards, Christian

How to use custom formatted HTML body [sf#12]

Reported by cado2010sf on 2016-10-20 12:29 UTC
Hi

We're using AIM nuget in our Web API project to send email notifications. Our email body contains custom formatted HTML, like links with hrefs and link text. We also need to separate lines with
. Aegis library seems to be formatting the HTML body on its own. For example, single carriage (CR/LF) returns are not honored, they are removed. Double CRLFs seem to be replaced with

and any custom formatted HTML like a link () or
seems to be getting HTML encoded.

I want to know how to format HTML content body but not have Aegis perform its own HTML encoding of the body.
Thanks!

-Srikanth

Problems with from-encoding

Hi,

as I had problems when using some characters in an extended from: field (e.g. "Max Müller [email protected]").
I repaced the line "buf.Append(MailMessage.From);" in SendMail() with "buf.Append(GetEncodedFromAddress());" and added the following code to SmtpSocketClient.cs

`
private object GetEncodedFromAddress()
{
var headersEncoding = MailMessage.HeadersEncoding ?? Encoding.UTF8;
if (Encoding.ASCII.Equals(headersEncoding))
{
return MailMessage.From;
}
else
{
byte[] bytes = headersEncoding.GetBytes(MailMessage.From.DisplayName);

	var encodingName = headersEncoding.BodyName.ToLower();
	string qpEncodedName = QuotedPrintableConverter.Encode(MailMessage.From.DisplayName);

	string encoded = "=?" + encodingName + "?Q?" + qpEncodedName + "?= <" + MailMessage.From.Address + ">";
	return encoded;
}

}
`

also I added the follwing class (from https://dotnet-snippets.de/snippet/quoted-printable-encoder/778) used by the function above:

`
using System.Text;

namespace AegisImplicitMail
{
public class QuotedPrintableConverter
{
private static string _Ascii7BitSigns;
private const string _equalsSign = "=";
private const string _defaultReplaceEqualSign = "=";

	/// <summary>
	/// Ctor.
	/// </summary>
	private QuotedPrintableConverter()
	{
		//do nothing
	}

	/// <summary>
	/// Encodes a not QP-Encoded string.
	/// </summary>
	/// <param name="value">The string which should be encoded.</param>
	/// <returns>The encoded string</returns>
	public static string Encode(string value)
	{
		return Encode(value, _defaultReplaceEqualSign);
	}

	/// <summary>
	/// Encodes a not QP-Encoded string.
	/// </summary>
	/// <param name="value">The string which should be encoded.</param>
	/// <param name="replaceEqualSign">The sign which should replace the "="-sign in front of 
	/// each QP-encoded sign.</param>
	/// <returns>The encoded string</returns>
	public static string Encode(string value, string replaceEqualSign)
	{
		//Alle nicht im Ascii-Zeichnsatz enthaltenen Zeichen werden ersetzt durch die hexadezimale 
		//Darstellung mit einem vorangestellten =
		//Bsp.: aus "ü" wird "=FC"
		//Bsp. mit Ersetzungszeichen "%"für das "=": aus "ü" wird "%FC"

		GetAllowedAsciiSigns();
		StringBuilder sb = new StringBuilder();
		foreach (char s in value)
		{
			if (_Ascii7BitSigns.LastIndexOf(s) > -1)
				sb.Append(s);
			else
			{

				string qp = string.Format("{0}{1}",
						_equalsSign,
						System.Convert.ToString(s, 16)).Replace(_equalsSign, replaceEqualSign);
				sb.Append(qp);
			}
		}

		return sb.ToString();
	}

	/// <summary>
	/// Gets a string which contains the first 128-characters (ANSII 7 bit).
	/// </summary>
	private static void GetAllowedAsciiSigns()
	{
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < 127; i++)
		{
			sb.Append(System.Convert.ToChar(i));
		}
		_Ascii7BitSigns = sb.ToString();
	}
}

}
`

PS: sorry, I could not get the code propperbly recogniced using the "Add code" formater

I can choose between various encodings (other than ASCII7 like "iso-8859-1") using the third parameter of System.Net.Mail.MailAddress(string address, string displayName, Encoding displayNameEncoding) when set the MimeMailMessage.From property.

Maybe you can check this and integrate such a feature in your code.

best regards, Christian

Create Gmail Sender [sf#3]

Reported by nilnull on 2014-09-22 04:04 UTC
Generate a component to send mails specifically for gmail

Error when adding attachment [sf#16]

Reported by rkmoray on 2018-07-25 12:53 UTC
I amd trying to add an attachment to an email, When the add attachment line is read, I get an object error.
Here is the code
var mymessage = new MimeMailMessage
{
From = new MimeMailAddress(Mail),
Subject = "Web Purchase Receipt " + DateTime.Now.ToString("yyyyMMdd"),
Body = "body"
};
mymessage.To.Add("[email protected]");
var mailer = new MimeMailer(Host, 465)
{
User = User,
Password = Pass,
EnableImplicitSsl = true,
AuthenticationMode = AuthenticationType.Base64
};
var a = new MimeAttachment("c:\temp\Integra POS.pdf")
{
//ContentType = new ContentType("application/pdf"),
ContentType = new ContentType("application/octet-stream"),

            Location = AttachmentLocation.Inline
        };
        AttachList.Add(a);

        foreach (Attachment t in AttachList)
        {

            mailer.MailMessage.Attachments.Add((MimeAttachment)t);//Error on the line
        }
        ((SmtpSocketClient)mailer).SslType = SslMode.Ssl;

        mailer.SendCompleted += SendCompleted;
        mailer.SendMailAsync(mymessage);

Sending Emails on TLS 1.2 [sf#13]

Reported by naveenpapagari on 2017-01-23 05:56 UTC
I have been using Aegis Implicit Mail (AIM) to send mails over ssl for some time. We have recently upgraded to TLS 1.2 and now i am not able to send any mails. I have been getting error saying - The client and server cannot communicate, because they do not possess a common algorithm. Need help on this ... Thank you

Content-Type text/html not set [sf#11]

Reported by ei5fuch5 on 2016-06-09 12:25 UTC
I can't set the Content-Type of the mail to text/html.

IsBodyHtml = true

and

var nvc = new NameValueCollection {{"Content-Type", "text/html"}};
Headers = { nvc }

are ignored by the lib. The Content-Type of the Mail is always:
Content-Type: multipart/mixed; boundary="32d5b61c-4617-4b20-aac7-06fa4f4ebbc5"

Mail Sender Factory [sf#1]

Reported by nilnull on 2014-09-20 12:39 UTC
Generate an abstract factory class for users to be able to handle all types of mails in one single class

Encoding [sf#4]

Reported by phnx47 on 2014-12-23 12:36 UTC
Custom encoding isn't supported.
Unicode is not correctly found and set in some languedges. (Please add your languedges in comments so we can add priorities and testings).

Need support for alternateviews [sf#15]

Reported by srikanthaj on 2018-02-02 03:40 UTC
Please add capability to send mailmessages with alternatevies, it helps is embed inline images with Linkedresources.

Add support for mono [sf#9]

Reported by nilnull on 2015-04-11 15:46 UTC
An attempt to send an email using implicit SSL with AIM currently results in the following error: Mono: The class System.Net.Security.EncryptionPolicy could not be loaded, used in System, Version=4.0.0.0, Culture=neutral
Whilst strictly speaking this is a Mono issue, AIM could easily implement a workaround like the one described at mono/mono#1399

Message-Id Header

Please update documentation, and eventually the code to take into account the automatic addition of a proper Message-Id as it may
happen that the first-hop SMTP server used to the send the email is not actively adding the missing header.

Be able to use streams as attachments [sf#7]

Reported by nilnull on 2015-04-06 12:52 UTC
One of the constructors for Attachment allows for supplying a content stream, but the constructors for MimeAttachment hide this and make it unusable.

Non async call

Is there a way to get any result/status information if using the SendMail instead of the SendMailAsync?
SendMail returns void.

Thanks.

Cannot use package on .NET 7 VS 2022

I installed the package using package manager "NuGet\Install-Package AIM -Version 1.1.1" and can that it is installed

However trying using AegisImplicitMail; gets me

he type or namespace name 'AegisImplicitMail' could not be found

What's wrong here ?

Email not send if attachment used [sf#17]

Reported by rkmoray on 2018-07-25 17:42 UTC
My issue at the moment,is if an attachment is being used, the email does not get send, and there is no error message. The file name is correct, I have verified that. Whith this code I get no email, but no error message as well.
Here is an example
string strdtfile = DateTime.Now.ToString("yyyyMMddHHmmss");
string FilePath = @Server.MapPath("~/Temp/" + strdtfile + ".pdf");
currentReport.ExportToPdf(FilePath);
var mymessage = new MimeMailMessage();
mymessage.From = new MimeMailAddress(Mail);
mymessage.Subject = "Web Purchase Receipt " + DateTime.Now.ToString("yyyyMMdd");
mymessage.To.Add(Session["email"].ToString());
mymessage.Body = "";
mymessage.IsBodyHtml = true;
mymessage.To.Add(Session["email"].ToString());
var mailer = new MimeMailer(Host, 465)
{
User = User,
Password = Pass,
EnableImplicitSsl = true,
AuthenticationMode = AuthenticationType.Base64
};

        mymessage.Attachments.Add(new MimeAttachment(FilePath));


        ((SmtpSocketClient)mailer).SslType = SslMode.Ssl;

        mailer.SendCompleted += SendCompleted;
        mailer.SendMailAsync(mymessage);

Improve call back and error handling [sf#2]

Reported by nilnull on 2014-09-20 12:41 UTC
Currently the asynchronous mail sending delegate function does not returns enough informations for implicit and smime mails. That should be improved

Date and Time Issues [sf#10]

Reported by nilnull on 2015-04-11 15:48 UTC
Some users have been complaining about the time and date of emails

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.