All Projects → doxakis → Mailbody

doxakis / Mailbody

Licence: mit
Create transactional email with a fluent interface (.net)

Programming Languages

csharp
926 projects

Projects that are alternatives of or similar to Mailbody

Fluentemail
All in one email sender for .NET. Supports popular senders (SendGrid, MailGun, etc) and Razor templates.
Stars: ✭ 1,888 (+1150.33%)
Mutual labels:  email, dotnetcore
Sendgrid Csharp
The Official Twilio SendGrid Led, Community Driven C#, .NetStandard, .NetCore API Library
Stars: ✭ 835 (+452.98%)
Mutual labels:  email, dotnetcore
H12y
The email service for when just "hey.com" isn't enough.
Stars: ✭ 139 (-7.95%)
Mutual labels:  email
Dotnetcore
.NET 5 Nuget Packages.
Stars: ✭ 146 (-3.31%)
Mutual labels:  dotnetcore
Phoenix swoosh
Swoosh <3 Phoenix
Stars: ✭ 145 (-3.97%)
Mutual labels:  email
Striker
Striker is an offensive information and vulnerability scanner.
Stars: ✭ 1,851 (+1125.83%)
Mutual labels:  email
Django Mail Templated
Send emails using Django template system
Stars: ✭ 146 (-3.31%)
Mutual labels:  email
Gman
A ruby gem to check if the owner of a given email address or website is working for THE MAN (a.k.a verifies government domains).
Stars: ✭ 137 (-9.27%)
Mutual labels:  email
Notifme Sdk
A Node.js library to send all kinds of transactional notifications.
Stars: ✭ 1,854 (+1127.81%)
Mutual labels:  email
Wp mail
Documentation for all the situations where WordPress core sends an email, how and when they happen, and how to filter or disable each one.
Stars: ✭ 144 (-4.64%)
Mutual labels:  email
Dotnetcore.samples
.NET Core Samples - Code it Yourself...
Stars: ✭ 147 (-2.65%)
Mutual labels:  dotnetcore
Django mail admin
The one and only django app to receive & send mail with templates and multiple configurations.
Stars: ✭ 140 (-7.28%)
Mutual labels:  email
Coravel
Near-zero config .NET Core micro-framework that makes advanced application features like Task Scheduling, Caching, Queuing, Event Broadcasting, and more a breeze!
Stars: ✭ 1,989 (+1217.22%)
Mutual labels:  dotnetcore
Modoboa
Mail hosting made simple
Stars: ✭ 1,998 (+1223.18%)
Mutual labels:  email
Magma
The magma server daemon, is an encrypted email system with support for SMTP, POP, IMAP, HTTP and MOLTEN,. Additional support for DMTP and DMAP is currently in active development.
Stars: ✭ 1,740 (+1052.32%)
Mutual labels:  email
Netbarcode
Barcode generation library written in C# and .NET Standard 2
Stars: ✭ 149 (-1.32%)
Mutual labels:  dotnetcore
Nlayerappv3
Domain Driven Design (DDD) N-LayeredArchitecture with .Net Core 2
Stars: ✭ 138 (-8.61%)
Mutual labels:  dotnetcore
Laravel Postmark
A Postmark adapter for Laravel
Stars: ✭ 143 (-5.3%)
Mutual labels:  email
Mattermail
Email Integration for Mattermost
Stars: ✭ 145 (-3.97%)
Mutual labels:  email
Data
Fast DB-independent DAL for .NET Core: abstract queries, SQL commands builder, schema-less data access, POCO mapping (micro-ORM).
Stars: ✭ 150 (-0.66%)
Mutual labels:  dotnetcore

MailBody Build Status NuGet Status

MailBody is a library for generating transactional email by using a fluent interface.

The current mail template is based on https://github.com/leemunroe/responsive-html-email-template (MIT License 2013 Lee Munroe)

Supported framework

  • dotnet core 1.0
  • .net framework 4.5 (c#, vb)

Install from Nuget

To get the latest version:

Install-Package MailBody

MailBody Editor

If you want to create email with the MailBody library while having a live preview, you can use the MailBody Editor

Preview

Quick Examples

Email Address Confirmation

C# syntax:

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

Visual Basic syntax:

Dim body As String = MailBody.CreateBody() _
    .Paragraph("Please confirm your email address by clicking the link below.") _
    .Paragraph("We may need to send you critical information about our service and it is important that we have an accurate email address.") _
    .Button("https://example.com/", "Confirm Email Address") _
    .Paragraph("— [Insert company name here]") _
    .ToString()

Preview

Password reset

var appName = "My app";

var body = MailBody
    .CreateBody()
    .Paragraph("Hi,")
    .Paragraph("You're receiving this email because someone requested a password reset for your user account at " + appName + ".")
    .Button("https://www.example.com/", "Reset password")
    .Paragraph("Thanks for using " + appName + "!")
    .Paragraph("— [Insert company name here]")
    .ToString();

Preview

Order confirmation

var products = new string[] { "1 x Product A", "2 x Product B", "3 x Product C" };

// Format product display.
var items = products.Select(item => MailBody.CreateBlock().Text(item));
            
var body = MailBody
    .CreateBody()
    .Title("Confirmation of your order")
    .Paragraph("Hello,")
    .Paragraph("We confirm having received your order.")
    .Paragraph("Here is the list of ordered items:")
    .UnorderedList(items)
    .Paragraph("Thank you for ordering from us!")
    .Paragraph("— [Insert company name here]")
    .ToString();

Preview

Notification

var productName = "ABC";
var productStatus = "available";
var productDescription = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sagittis nisl ut tellus egestas facilisis. Nulla eget erat dictum, facilisis libero sit amet, sollicitudin tortor. Morbi iaculis, urna eu tincidunt dapibus, sapien ex dictum nibh, non congue urna tellus vitae risus.";
var components = new string[] { "Part A", "Part B" };
            
// Format product display.
var items = components.Select(item => MailBody.CreateBlock().Text(item));
            
var body = MailBody
    .CreateBody()
    .Paragraph("Hello,")
    .Paragraph("The product " + productName + " is now " + productStatus + ".")
    .SubTitle("Here is the product summary:")
    .Paragraph(MailBody.CreateBlock()
        .StrongText("Product name: ").Text(productName))
    .Paragraph(MailBody.CreateBlock()
        .StrongText("Description: ").Text(productDescription))
    .Paragraph(MailBody.CreateBlock()
        .StrongText("Components:"))
    .UnorderedList(items)
    .Paragraph("— [Insert company name here]")
    .ToString();

Preview

With footer

var footer = MailBody
    .CreateBlock()
    .Text("Follow ")
    .Link("http://twitter.com/example", "@Example")
    .Text(" on Twitter.");

var body = MailBody
    .CreateBody(footer)
    .Paragraph("Please confirm your email address by clicking the link below.")
    .Paragraph("We may need to send you critical information about our service and it is important that we have an accurate email address.")
    .Button("https://www.example.com/", "Confirm Email Address")
    .Paragraph("— [Insert company name here]")
    .ToString();

Preview

With image

Please note You can use CID Embedded Images, Base64 Encoding or use absolute url. Image may not appear on all email client. So, make sure to do some tests.

var body = MailBody
    .CreateBody()
    .Image("https://placehold.it/540x70/ffffff/e8117f?text=My+logo", "My company name")
    .Paragraph("Please confirm your email address by clicking the link below.")
    .Paragraph("We may need to send you critical information about our service and it is important that we have an accurate email address.")
    .Button("https://example.com/", "Confirm Email Address")
    .Paragraph("— [Insert company name here]")
    .ToString();

Preview

Custom theme & Raw html

var template = MailBodyTemplate.GetDefaultTemplate();
template
    .Paragraph(m =>
        "<p style='" +
        (m.IsProperty(() => m.Attributes.color) ? $"color:{m.Attributes.color};" : string.Empty) +
        (m.IsProperty(() => m.Attributes.backgroundColor) ? $"background-color:{m.Attributes.backgroundColor};" : string.Empty) +
        $"'>{m.Content}</p>")
    .Body(m => "<html><body>" + m.Content + "<br />" + m.Footer + "</body></html>")
    .Text(m =>
        $"<span style='" +
        (m.IsProperty(() => m.Attributes.color) ? $"color:{m.Attributes.color};" : string.Empty) +
        (m.IsProperty(() => m.Attributes.backgroundColor) ? $"background-color:{m.Attributes.backgroundColor};" : string.Empty) +
        (m.IsProperty(() => m.Attributes.fontWeight) ? $"font-weight:{m.Attributes.fontWeight};" : string.Empty) +
        $"'>{m.Content}</span>");

var footer = MailBody
    .CreateBlock()
    .Text("Follow ", new { color = "red"})
    .Link("http://twitter.com/example", "@Example")
    .Text(" on Twitter.", new { color = "#009900", backgroundColor = "#CCCCCC", fontWeight = "bold" });
            
var body = MailBody
    .CreateBody(template, footer)
    .Paragraph("Please confirm your email address by clicking the link below.")
    .Raw("<p>We may need to send you <strong>critical information</strong> about our service and it is important that we have an accurate email address.</p>")
    .Button("https://www.example.com/", "Confirm Email Address")
    .Paragraph("— [Insert company name here]", new { color = "white", backgroundColor = "black" })
    .ToString();

Preview

Another way to create your email

var body = MailBody.CreateBody();

body.Paragraph("Hi,")
    .Paragraph("First paragraph..");

// Your code

body.Button("https://www.example.com/", "First button");
body.Paragraph("Another paragraph..");

// Your code

body.Button("https://www.example.com/", "Second button")
    .Paragraph("— [Insert company name here]");

var htmlBody = body.ToString();

Preview

Override the default template

This example is based on Postmark templates.

var template = MailBodyTemplate.GetDefaultTemplate()
    .Paragraph(m => $"<p style='font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;'>{m.Content}</p>")
    .Link(m => $"<a href='{m.Link}'>{m.Content}</a>")
    .Title(m => $"<h1>{m.Content}</h1>")
    .SubTitle(m => $"<h2>{m.Content}</h2>")
    .Text(m => $"{m.Content}")
    .StrongText(m => $"<strong>{m.Content}</strong>")
    .UnorderedList(m => $"<ul>{m.Content}</ul>")
    .OrderedList(m => $"<ol>{m.Content}</ol>")
    .ListItem(m => $"<li>{m.Content}</li>")
    .LineBreak(m => $"</br>")
    .Button(m => @"<table class='body-action' align='center' width='100%' cellpadding='0' cellspacing='0'>
            <tr>
                <td align='center'>
                <table width='100%' border='0' cellspacing='0' cellpadding='0'>
                    <tr>
                    <td align='center'>
                        <table border='0' cellspacing='0' cellpadding='0'>
                        <tr>
                            <td>
                            <a href='" + m.Link + @"' class='button button--' target='_blank'>" + m.Content + @"</a>
                            </td>
                        </tr>
                        </table>
                    </td>
                    </tr>
                </table>
                </td>
            </tr>
            </table>")
    .Block(m => m.Content)
    .Body(m => @"<html>... (see the examples for the complete source) ...</html>");

var body = MailBody
    .CreateBody(template)
    .Paragraph("Please confirm your email address by clicking the link below.")
    .Paragraph("We may need to send you critical information about our service and it is important that we have an accurate email address.")
    .Button("https://example.com/", "Confirm Email Address")
    .Paragraph("— [Insert company name here]")
    .ToString();

Preview

Copyright and license

Code released under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].