Bsixmail.netcore 1.0.1

.NET Core 2.0
dotnet add package Bsixmail.netcore --version 1.0.1
NuGet\Install-Package Bsixmail.netcore -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Bsixmail.netcore" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Bsixmail.netcore --version 1.0.1
#r "nuget: Bsixmail.netcore, 1.0.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Bsixmail.netcore as a Cake Addin
#addin nuget:?package=Bsixmail.netcore&version=1.0.1

// Install Bsixmail.netcore as a Cake Tool
#tool nuget:?package=Bsixmail.netcore&version=1.0.1

Mailer template and helper for asp.netcore 2.0 above

First step you need to add and edit this in your appsettings.json

  "BsixMail": {
    "UserName": "yourmail@domain.com",
    "Password": "yourpassword",
    "Server": "smtp.yourservermail.com",
    "Port": "587",
    "UrlBase": "https://www.yourdomain.com" // your website domain (optional you can leave it empty)
  }

Lets call the bsixmail inside your contoller or method

var mailer = new BsixMailer();

Now you can use it, see the examples below :

This is for send on the fly. Variable _Base just optional if you want to configure approval, you need to configure your domain, so public can access your public url not your localhost

var _Base = _config.GetSection("BsixMail").GetSection("UrlBase").Value;           
mailer.BuildBody(new
{
  Message = "hello from bsix aproval",
  UrlApprove = string.Format("{0}/{1}/{2}", _Base, "Approve", "yes"),
  UrlReject = string.Format("{0}/{1}/{2}", _Base, "Approve", "no") 
}, "default.txt") // Your template mail located inside BsixMail folder
.EmailTo("mailto@example.com")
.EmailSubject("This is subject")
.Send();

Sending mail in background task

mailer.BuildBody(new
{
  Message = "hello from bsix" // You can bind this with your model, its just example
}, "default.txt")  // Your template mail located inside BsixMail folder
.EmailTo("mailto@example.com")
.EmailSubject("This is subject")
.SendBackground();

You can add or edit default.txt with your own template, and bind it to your model, example

public class Mymodel 
{
  public string Name {get; set;}
}

Then your defaul.txt or mytemplate.html which is you just created with your own inside BsixMail Folder example template

Hi {{Name}} i`m from Bsixmail

And see how to use it

var myModel =  new Mymodel() { Name = "Ihsan" };

mailer.BuildBody(myModel, "mytemplate.txt")  // Your template mail located inside BsixMail folder
.EmailTo("mailto@example.com")
.EmailSubject("This is subject")
.SendBackground();

You also can trace if email not sent in BsixMail folder

If you want to take a look the source https://github.com/ihsanbsix/Bsix-MailSender

Thats it

Need help? just go to github repo and create issue

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 net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 384 12/10/2019
1.0.0 323 12/10/2019

Update document