Skip to content

Simplify.Mail

Alexanderius edited this page Nov 20, 2025 · 7 revisions

Simplify.Mail Documentation

Provides IMailSender interface and MailSender implementation for simple e-mail sending.

Available at NuGet as binary package

Quick Start Usage

{
    "MailSenderSettings": {
        "SmtpServerAddress": "server name or ip address",
        "SmtpUserName": "user name",
        "SmtpUserPassword": "user password"
    }
}

Simple mail sending example

var config = new ConfigurationBuilder()
			.AddJsonFile("appsettings.json")
			.Build();

new MailSender(config).Send("mymail@somedomain.com", "mailrecepient@somedomain.com", "Mail subject!", "Mail message, can be full HTML page");

Anti-Spam filter

Mail sender includes anti-spam message pool, which is ON by default and default pool message life time is 120 min. Whenever message is sending via MailSender, it's body will be added to anti-spam pool. At the next time, when another message with the same body is sent in next 120 minutes after first message is sent then the message will not be sent. It is useful, for example, if you have some windows service, which is doing some processing every minute and so on, and it is started to throwing same exceptions every minute, then the MailSender will prevent it from spamming. Anti-spam pool can be turned off via configuration.

You can specify body for anti-spam pool checking separately from mail message body. For example, if you have some "current time" information in your body, which will be changing every time message sends, and anyway your want to use anti-spam pool, then you can provide that message body without time information as separated parameter, for example:

var message = "Some problem was happened at: ";
mailSender.Send("mymail@somedomain.com", "mailrecepient@somedomain.com", "Some problem was happened at: ", message + DateTime.Now, message);

Multiple recepients, carbon copy recipients and attachements

mailSender.Send("mymail@somedomain.com", new List<string> { "address1@somedomain.com", "address2@somedomain.com" }, new List<string> { "address3@somedomain.com", "address4@somedomain.com" },
				"Mail subject!", "Mail message, can be full HTML page", null,
				new Attachment(ms, "Attachement title.xls", "application/vnd.ms-excel"));

Send message to recipients separately

mailSender.SendSeparately("mymail@somedomain.com", new List<string> { "address1@somedomain.com", "address2@somedomain.com" }, "Mail subject!", "Mail message, can be full HTML page");

All available options example

{
    "MailSenderSettings": {
      "SmtpServerAddress": "server name or ip address",
      "SmtpUserName": "user name",
      "SmtpUserPassword": "user password",
      "SmtpServerPortNumber": "25",
      "AntiSpamMessagesPoolOn": "true",
      "AntiSpamPoolMessageLifeTime": "120",
      "EnableSsl": "true"
    }
}

Migration Notes from v1 to v2

Breaking Changes

  • Attachment[] → MimeEntity[] parameters
  • MailMessage → MimeMessage parameters
  • Async methods now have optional CancellationToken parameters

Example Migration

Before (System.Net.Mail):

using System.Net.Mail;

var attachment = new Attachment("file.pdf");

sender.Send("from@example.com", "to@example.com", "Subject", "Body", null, attachment);

After (MailKit):

using MimeKit;

var attachment = new MimePart("application", "pdf") {
	Content = new MimeContent(File.OpenRead("file.pdf")),
	FileName = "file.pdf"
};

sender.Send("from@example.com", "to@example.com", "Subject", "Body", null, attachment);

Clone this wiki locally