crystal-email v0.4.6

Simple e-mail sending library
  • v0.4.6 - January 10, 2020
  • v0.4.5 - December 17, 2019
  • v0.4.3 - October 11, 2019
  • v0.4.2 - October 4, 2019
  • v0.4.1 - February 11, 2019

EMail for Crystal

Build Status

Simple email sending library for the Crystal programming language.

You can:

  • construct an email with a plain text message, a HTML message and/or some attachment files.
  • include resources(e.g. images) used in the HTML message.
  • set multiple recipients to the email.
  • use multibyte characters(only UTF-8) in the email.
  • send the email by using local or remote SMTP server.
  • use TLS connection by STARTTLS command.
  • use SMTP-AUTH by AUTH PLAIN or AUTH LOGIN when using TLS.
  • send multiple emails concurrently by using multiple smtp connections.

You can not:

  • use ESMTP features except those mentioned above.


First, add the dependency to your shard.yml:

    github: arcage/crystal-email

Then, run shards install


To send a minimal email message:

require "email"

# Create email message
email =
email.from    ""      ""
email.subject "Subject of the mail"
email.message <<-EOM
  Message body of the mail.

  Your Signature

# Set SMTP client configuration
config ="", 25)

# Create SMTP client object
client =

client.start do
  # In this block, default receiver is client

This code will output log entries to STDOUT as follows:

2018/01/25 20:35:09 [crystal-email/12347] INFO [EMail_Client] Start TCP session to
2018/01/25 20:35:10 [crystal-email/12347] INFO [EMail_Client] Successfully sent a message from <> to 1 recipient(s)
2018/01/25 20:35:10 [crystal-email/12347] INFO [EMail_Client] Close TCP session to

Client configs

You can set some connection settings to EMail::Client::Config object.

That can make SMTP connection to use TLS / SMTP AUTH, or output more detailed log message.

See EMail::Client::Config for more details.

Email message

You can set more email headers to EMail::Message object.

And, you can also send emails including attachment files, HTML message, and/or resource files related message body(e.g. image file for HTML message).

See EMail::Message for more details.

Concurrent sending

By using EMail::ConcurrentSender object, you can concurrently send multiple messages by multiple connections.

rcpt_list = ["", "", "", ""]

# Set SMTP client configuration
config ="", 25)

# Create concurrent sender object
sender =

# Sending emails with concurrently 3 connections.
sender.number_of_connections = 3

# Sending max 10 emails by 1 connection.
sender.messages_per_connection = 10

# Start email sending.
sender.start do
  # In this block, default receiver is sender
  rcpts_list.each do |rcpt_to|
    # Create email message
    mail =
    mail.from "" rcpt_to
    mail.subject "Concurrent email sending"
    mail.message "message to #{rcpt_to}"
    # Enqueue the email to sender
    enqueue mail

See EMail::ConcurrentSender for more details.


  • arcage ʕ·ᴥ·ʔAKJ - creator, maintainer


Thank you for valuable contributions.

github statistic
  • 78
  • 8
  • 8
  • 0
  • about 1 month ago
  • November 9, 2016

MIT License

Synced at

Thu, 20 Feb 2020 07:16:52 GMT