FluentEmailer.LJShole
1.1.1
dotnet add package FluentEmailer.LJShole --version 1.1.1
NuGet\Install-Package FluentEmailer.LJShole -Version 1.1.1
<PackageReference Include="FluentEmailer.LJShole" Version="1.1.1" />
<PackageVersion Include="FluentEmailer.LJShole" Version="1.1.1" />
<PackageReference Include="FluentEmailer.LJShole" />
paket add FluentEmailer.LJShole --version 1.1.1
#r "nuget: FluentEmailer.LJShole, 1.1.1"
#:package FluentEmailer.LJShole@1.1.1
#addin nuget:?package=FluentEmailer.LJShole&version=1.1.1
#tool nuget:?package=FluentEmailer.LJShole&version=1.1.1
FluentEmailer
Fluent API to send emails in a .NET Core application using your own SMTP settings
V 1.1.1 Changes
This change addresses an issue with setting the Bcc
and Cc
email addresses before this change. These were added onto the To
email list.
This change also includes a change to the .FromMailAddresses
method; since an email can only originate from one email address, this method should be named accordingly i.e in singular form not plural.
Usage (using string as body of email)
_fluentEmail
.UsingSMTPServer(hostName, portNumber, userName, password, sslRequired)
.Message("Email Subject", new List<MailAddress> { new(toEmail) }, new(userName, "Email Display Name"))
.FromMailAddress(new MailAddress(***userName***))
.Body("Test body content")
.Send();
V 1.1.0 Changes
Future versions of the application / package will provide support for SendGrid, with this in mind, I have introduced breaking changes which pave way for the coming support. In addition, the change aims to make using the package much more intuitive and seemless. We do still support dependency injection. Simply add sample code below in your program.cs and import the FluentEmailer.LJShole
namespace in the program.cs file.
builder.Services.AddFluentEmailer()
This will allow you to inject the IFluentEmail
interface which you can use your code.
Usage (using string as body of email)
_fluentEmail
.UsingSMTPServer(hostName, portNumber, userName, password, sslRequired)
.Message("Email Subject", new List<MailAddress> { new(toEmail) }, new(userName, "Email Display Name"))
.FromMailAddresses(new MailAddress(***userName***))
.CcMailAddresses([new MailAddress(***ccEmail***)])
.BccMailAddresses([new MailAddress(***bccEmail***)])
.AddAttachments([new($"{Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SamplePDF.pdf")}")])
.Body("Test body content")
.Send();
Usage (providing a template file for the body of the email)
var templateValues = new Dictionary<string, string> { { "{{subject}}", "Testing Message" }, { "{{body}}", "<section><h2>This is</h2><p>Welcome to our world</p></section>" } };
_fluentEmail
.UsingSMTPServer(hostName, portNumber, userName, password, sslRequired)
.Message("Email Subject", new List<MailAddress> { new(toEmail) }, new(userName, "Email Display Name"))
.FromMailAddresses(new MailAddress(***userName***))
.CcMailAddresses([new MailAddress(***ccEmail***)])
.BccMailAddresses([new MailAddress(***bccEmail***)])
.AddAttachments([new($"{Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SamplePDF.pdf")}")])
.Body(templateValues, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestHtmlPage.html"))
.Send();
V 1.0.4
Usage (Simple string as body of the email)
new Mailer()
.Message()
.WithSubject("Email Subject")
.AddFromMailAddresses(new MailAddress(userName))
.AddToMailAddresses(new List<MailAddress> { new MailAddress(toEmail) })
.WithBody()
.UsingString("Email body as string")
.SetBodyIsHtmlFlag()
.WithCredentials()
.UsingHostServer(hostName)
.OnPortNumber(portNumber)
.WithUserName(userName)
.WithPassword(password)
.Send();
hostName The SMPT/IMAP server you'll be using to send emails from. <br/> portNumber The port number used by the hostName<br/> userName The email address you'll be using to send emails from as configured on *hostName. <br/> password The password used to log in when accessing the email address (userName)<br/>
Usage (Providing a template file)
new Mailer()
.Message()
.WithSubject("Email Subject")
.AddFromMailAddresses(new MailAddress(userName))
.AddToMailAddresses(new List<MailAddress> { new MailAddress(***toEmail***) })
.AddCcMailAddresses(new List<MailAddress> { new MailAddress(***ccEmail***) })
.AddBccMailAddresses(new List<MailAddress> { new MailAddress(***bccEmail***) })
.WithBody()
.UsingEmailTemplate($"{Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"TestHtmlPage.html")}")
.UsingTemplateDictionary(new Dictionary<string, string> { { "{{subject}}","Testing Message"}, { "{{body}}", "<section><h2>This is</h2><p>Welcome to our world</p></section>" } })
.CompileTemplate()
.SetBodyIsHtmlFlag()
.WithCredentials()
.UsingHostServer(hostName)
.OnPortNumber(portNumber)
.WithUserName(userName)
.WithPassword(password)
.Send();
This usage requires a Dictionary<string,string> where the keys in the dictionary represent placeholders in the template to be replaced by their respective values.<br/>
Usage (Adding Attachments)
new Mailer()
.Message()
.WithSubject("Mail Subject Template")
.AddFromMailAddresses(new MailAddress(userName,"Fluent Email"))
.AddToMailAddresses(new List<MailAddress> { new MailAddress(***toEmail***) })
.AddCcMailAddresses(new List<MailAddress> { new MailAddress(***ccEmail***) })
.AddBccMailAddresses(new List<MailAddress> { new MailAddress(***bccEmail***) })
.WithAttachments(new List<Attachment> { new Attachment($"{Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SamplePDF.pdf")}") })
.WithBody()
.UsingEmailTemplate($"{Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"TestHtmlPage.html")}")
.UsingTemplateDictionary(new Dictionary<string, string> { { "{{subject}}","Testing Message"}, { "{{body}}", "<section><h2>This is</h2><p>Welcome to our world</p></section>" } })
.CompileTemplate()
.SetBodyIsHtmlFlag()
.WithCredentials()
.UsingHostServer(hostName)
.OnPortNumber(portNumber)
.WithUserName(userName)
.WithPassword(password)
.Send();
V 1.0.3 Changes
new Mailer()
.SetUpMessage()
.WithSubject("Mail Subject")
.AddFromMailAddresses(new MailAddress(userName, "Fluent Email - No Attachments - With ReplyTo"))
.AddToMailAddresses(new List<MailAddress> { new MailAddress(toEmail) })
.SetSubjectEncoding(Encoding.UTF8)
.WithReplyTo(new MailAddress("info@creativemode.co.za"))
.SetUpBody()
.SetBodyEncoding(Encoding.UTF8)
.SetBodyTransferEncoding(TransferEncoding.Unknown)
.Body()
.UsingString("This is me Testing")
.SetBodyIsHtmlFlag()
.SetPriority(MailPriority.Normal)
.WithCredentials()
.UsingHostServer(hostName)
.OnPortNumber(portNumber)
.WithUserName(userName)
.WithPassword(password)
.Send();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
V 1.1.1 Changes
This change addresses an issue with setting the Bcc and Cc email addresses before this change. These were added onto the To email list.
This change also includes a change to the .FromMailAddresses method; since an email can only originate from one email address, this method should be named accordingly i.e in singular form not plural.
V 1.1.0 Changes
- Future versions of the application / package will provide support for SendGrid, with this in mind, I have introduced breaking changes which pave way for the coming support. In addition, the change aims to make using the package much more intuitive and seemless. We do still support dependency injection.
V1.0.4
- Added an overload when specifying the template location to allow the user to provide the templateValues on the same line of code.
V 1.0.3
- Added support for Reply-To field,
- Support for subject encoding.
- Support for both body encoding and body transfer encoding.