MailBody.Core 0.5.0

dotnet add package MailBody.Core --version 0.5.0
NuGet\Install-Package MailBody.Core -Version 0.5.0
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="MailBody.Core" Version="0.5.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MailBody.Core --version 0.5.0
#r "nuget: MailBody.Core, 0.5.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MailBody.Core as a Cake Addin
#addin nuget:?package=MailBody.Core&version=0.5.0

// Install MailBody.Core as a Cake Tool
#tool nuget:?package=MailBody.Core&version=0.5.0

MailBody.Core

Generate transactional emails such as forget password, order completed, etc.

How to Use

Use the MailBodyBuilder class to generate your email.

var html = new MailBodyBuilder()
           .WithDefaultLayout()
           .WithParagraph("Please confirm your email address by clicking the link below.")
           .WithParagraph("We may need to send you critical information about our service and it is important that we have an accurate email address.")
           .WithButton("https://example.com/", "Confirm Email Address")
           .WithParagraph("— [Insert company name here]")
           .ToHtml();

Use the MailBlockBuilder class to generate HTML. This can be useful for nested content scenarios; for example, you need to place an image inside an a tag.

var image = new MailBlockBuilder()
    .WithImage("sample.png", "sample")
    .ToHtml();


var html = new MailBodyBuilder()
           .WithDefaultLayout()
           .WithParagraph("Please click on the image to download your item.")
           .WithLink(image, "www.example.com/download");
           
// or

var html = new MailBodyBuilder()
           .WithDefaultLayout()
           .WithParagraph("Please click on the image to download your item.")
           .WithLink(builder => builder.WithImage("sample.png", "sample"), "www.example.com/download");           

Extensibility

Custom Elements

You can add your element by implementing IMailElement and passing it to the builder using WithElement() method. The example below demonstrates how to add the horizontal element.

// Implement the IMailElement
public class HorizontalLineElement : IMailElement
{
    public string ToHtml()
    {
        return "<hr>";
    }
}

// Pass your element to the builder
var html = new MailBodyBuilder()
           .WithParagraph("Below there is a horizontal line.")
           .WithElement(new HorizontalLineElement())
           .ToHtml();

Custom Layout

You can add your custom layout by implementing IMailLayout and passing it to the builder using WithLayout() method.

// Implement the IMailElement
public class CustomLayout : IMailLayout
{
    public string ToHtml(string content)
    {
        return $@"<!DOCTYPE html>
        <html>
            <head>
                <title>Custom Layout</title>
            </head>
            
            <body>
            
                {content}
            
            </body>
        </html>"
    }
}


// Pass your layout to the builder
var html = new MailBodyBuilder()
           .WithLayout(new CustomLayout())
           .WithParagraph("Below there is a horizontal line.")
           .ToHtml();
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

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
0.5.0 452 12/6/2021
0.4.0 271 12/6/2021
0.3.0 267 12/5/2021
0.2.0 279 12/3/2021
0.1.0 847 11/29/2021