MailBody.Core 0.4.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package MailBody.Core --version 0.4.0                
NuGet\Install-Package MailBody.Core -Version 0.4.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.4.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MailBody.Core --version 0.4.0                
#r "nuget: MailBody.Core, 0.4.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.4.0

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

<h1 align="center"> <br> <a href="https://github.com/litenova/MailBody.Core"> <img alt="MailBody.Core Logo" src="assets/logo/icon.png"> </a> <br> MailBody.Core <br> </h1>

<h4 align="center">This is a complete and simplified rewrite of <a href="https://github.com/doxakis/MailBody">MailBody</a> in .NET 6</h4> <p align="center">Generate transactional emails such as forget password, order completed, etc.</p>

<p align="center"> <a href="https://github.com/litenova/MailBody.Core/actions/workflows/dotnet-core.yml"> <img src="https://github.com/litenova/MailBody.Core/actions/workflows/dotnet-core.yml/badge.svg?branch=main"> </a> <a href="https://www.nuget.org/packages/MailBody.Core"> <img src="https://img.shields.io/nuget/v/MailBody.Core"> </a> </p>

<p align="center"> <a href="#installation">Installation</a> • <a href="#how-to-use">How To Use</a> • <a href="#how-to-use">Showcases</a> • <a href="#extensibility">Extensibility</a> </p>

Installation

Install with NuGet:

dotnet add package MailBody.Core

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");           

Showcases

The picture below is a example of generated email using default layout.

MailBody.Core Showcase

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 500 12/6/2021
0.4.0 295 12/6/2021
0.3.0 292 12/5/2021
0.2.0 298 12/3/2021
0.1.0 872 11/29/2021