-
Notifications
You must be signed in to change notification settings - Fork 18
Home
ʕ·ᴥ·ʔAKJ edited this page Oct 16, 2018
·
1 revision
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
orAUTH LOGIN
when using TLS. - send multiple emails concurrently by using multiple smtp connections.
You can not:
- use ESMTP features except those mentioned above.
# send simple 1 message
require "email"
EMail.send("your.mx.server.name", 25) do
# [*] : useable multiple times
# required
subject "Subject of the mail"
from "[email protected]" # [*]
to "[email protected]" # [*]
# optional
cc "[email protected]" # [*]
bcc "[email protected]" # [*]
reply_to "[email protected]" # [*]
sender "[email protected]"
return_path "[email protected]"
envelope_from "[email protected]"
# required at least one `message`, `message_html` or `attach`
message <<-EOM
Message body of the mail.
--
Your Signature
EOM
attach "./attachment.docx" # [*]
# HTML email support
# `message_resource` works almost same as `attach`, expect it requires `cid:` argument.
message_html <<-EOM
<html>
<body>
<h1>Message body of the mail.</h1>
<img src="cid:[email protected]">
<footer>
Your Signature
</footer>
</body>
</html>
EOM
message_resource "./logo.png", cid: "[email protected]" # [*]
end
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 your.mx.server.name:25
2018/01/25 20:35:10 [crystal-email/12347] INFO [EMail_Client] Successfully sent a message from <[email protected]> to 3 recipient(s)
2018/01/25 20:35:10 [crystal-email/12347] INFO [EMail_Client] Close TCP session to your.mx.server.name:25