Skip to content
Send emails and text messages via the same API in C#
Branch: master
Clone or download
Latest commit 8b66e4c Nov 19, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
Butterfly.Message.Aws.Test Changes Oct 16, 2019
Butterfly.Message.Aws Changes Nov 19, 2019
Butterfly.Message.Test Changes Oct 21, 2019
Butterfly.Message.Twilio.Test Changes Oct 19, 2019
Butterfly.Message.Twilio Changes Nov 19, 2019
Butterfly.Message Changes Nov 19, 2019
docfx_project Changes Nov 19, 2019
docs Changes Nov 19, 2019
img Changes Oct 15, 2019
.gitattributes Changes Oct 15, 2019
.gitignore Changes Oct 15, 2019
Butterfly.Message.sln Changes Oct 15, 2019 Changes Oct 15, 2019
LICENSE Changes Oct 15, 2019 Changes Oct 21, 2019

Butterfly.Message Butterfly Logo

Send emails and text messages via the same API in C#

Install from Nuget

Name Package Install
Butterfly.Message nuget nuget install Butterfly.Message
Butterfly.Message.Aws nuget nuget install Butterfly.Message.Aws
Butterfly.Message.Twilio nuget nuget install Butterfly.Message.Twilio

Install from Source Code

git clone


Any files parsed with the .liquid extension will use the excellent Scriban template engine which is based on the Liquid template language.

// Parse messages
var sendMessageFileParser = new SendMessageFileParser();
var welcomeEmailSendMessage = sendMessageFileParser.Parse("welcome-email.liquid");
var welcomeTextSendMessage = sendMessageFileParser.Parse("welcome-text.liquid");

// Setup notify manager
var sendMessageQueueManager = new SendMessageQueueManager(
    emailMessageSender: new AwsSesEmailMessageSender(options.AwsAccessKeyId, options.AwsSecretAccessKey),
    textMessageSender: new TwilioTextMessageSender(options.TwilioAccountSid, options.TwilioAuthToken)

// Send welcome email
var welcomeEmail = welcomeEmailSendMessage.Evaluate(new Dict {
    ["first_name"] = "Kent",
    ["to"] = "",

// Send welcome text
var welcomeText = welcomeTextSendMessage.Evaluate(new Dict {
    ["first_name"] = "Kent",
    ["to"] = "+13165551212",

Example of the welcome-email.liquid file...

From: Kent Johnson <>
To: {{ first_name }} <{{ to }}>
Subject: Welcome

Hello, {{ user.first_name }}.  To get started, do these things. 

Example of the welcome-text.liquid file...

From: +13165551212
To: {{ to }}

Hello, {{ user.first_name }}.  To get started, do these things. 

While any database engine supported by Butterfly.Db can be used, here is the MySQL syntax for creating the required tables...

CREATE TABLE send_message (
  id varchar(50) NOT NULL,
  message_type tinyint(4) NOT NULL,
  message_priority tinyint(4) NOT NULL,
  message_from varchar(255) NOT NULL,
  message_to varchar(1024) NOT NULL,
  message_subject varchar(255) DEFAULT NULL,
  message_body_text mediumtext,
  message_body_html mediumtext,
  extra_json varchar(255) DEFAULT NULL,
  sent_at int(11) DEFAULT NULL,
  send_error varchar(255) DEFAULT NULL,
  sent_message_id varchar(255) DEFAULT NULL,
  created_at int(11) NOT NULL,
  UNIQUE KEY sent_message_id (sent_message_id),
  KEY other (message_type,sent_at,message_priority,created_at)

CREATE TABLE send_verify (
  contact VARCHAR(255) NOT NULL,
  verify_code INT NOT NULL,
  expires_at INT NOT NULL,
  created_at INT NOT NULL,
  updated_at INT NOT NULL,
  UNIQUE KEY contact (contact)


If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are warmly welcome.


The code is licensed under the Mozilla Public License 2.0.

You can’t perform that action at this time.