Simplify.Mail
1.5.2
Install-Package Simplify.Mail -Version 1.5.2
dotnet add package Simplify.Mail --version 1.5.2
<PackageReference Include="Simplify.Mail" Version="1.5.2" />
paket add Simplify.Mail --version 1.5.2
#r "nuget: Simplify.Mail, 1.5.2"
// Install Simplify.Mail as a Cake Addin
#addin nuget:?package=Simplify.Mail&version=1.5.2
// Install Simplify.Mail as a Cake Tool
#tool nuget:?package=Simplify.Mail&version=1.5.2
Simplify.Mail Documentation
Provides IMailSender
interface and MailSender
implementation for simple e-mail sending.
Available at NuGet as binary package
Quick Start Usage
MailSender.Default
ambient context provides default mail sender.
By default it initializes from App.config
or Web.config
file with three required settings:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="MailSenderSettings" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<MailSenderSettings>
<add key="SmtpServerAddress" value="server name or ip address"/>
<add key="SmtpUserName" value="user name"/>
<add key="SmtpUserPassword" value="user password"/>
</MailSenderSettings>
</configuration>
Simple mail sending example
MailSender.Default.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.Default.Send("mymail@somedomain.com", "mailrecepient@somedomain.com", "Some problem was happened at: ", message + DateTime.Now, message);
Multiple recepients, carbon copy recipients and attachements
MailSender.Default.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.Default.SendSeparately("mymail@somedomain.com", new List<string> { "address1@somedomain.com", "address2@somedomain.com" }, "Mail subject!", "Mail message, can be full HTML page");
Custom/Manual initialization
Specifying settings section in config file
MailSender(string configurationSectionName = "MailSenderSettings")
Passing custom parameters
MailSender(string smtpServerAddress, int smtpServerPortNumber, string smtpUserName, string smtpUserPassword,
bool enableSsl = false, bool antiSpamMessagesPoolOn = true, int antiSpamPoolMessageLifeTime = 125)
Passing 'IMailSenderSettings' with any implementation
MailSender(IMailSenderSettings mailSenderSettings)
Instantiating with the Microsoft.Extensions.Configuration
IConfiguration
implementation with ability to specify settings section name
public MailSender(IConfiguration configuration, string configurationSectionName = "MailSenderSettings")
IConfiguration settings based on appsettings.json example:
{
"MailSenderSettings":
{
"SmtpServerAddress": "server name or ip address",
"SmtpUserName": "user name",
"SmtpUserPassword": "user password"
}
}
All available options example
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="MailSenderSettings" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<MailSenderSettings>
<add key="SmtpServerAddress" value="server name or ip address"/>
<add key="SmtpUserName" value="user name"/>
<add key="SmtpUserPassword" value="user password"/>
<add key="SmtpServerPortNumber" value="25"/>
<add key="AntiSpamMessagesPoolOn" value="true"/>
<add key="AntiSpamPoolMessageLifeTime" value="120"/>
<add key="EnableSsl" value="true"/>
</MailSenderSettings>
</configuration>
Product | Versions |
---|---|
.NET | net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows |
.NET Core | netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1 |
.NET Standard | netstandard2.0 netstandard2.1 |
.NET Framework | net461 net462 net463 net47 net471 net472 net48 |
MonoAndroid | monoandroid |
MonoMac | monomac |
MonoTouch | monotouch |
Tizen | tizen40 tizen60 |
Xamarin.iOS | xamarinios |
Xamarin.Mac | xamarinmac |
Xamarin.TVOS | xamarintvos |
Xamarin.WatchOS | xamarinwatchos |
-
.NETFramework 4.6.2
- Microsoft.Extensions.Configuration (>= 3.1.24)
-
.NETStandard 2.0
- Microsoft.Extensions.Configuration (>= 3.1.24)
- System.Configuration.ConfigurationManager (>= 4.7.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.