Erlang and SMTP: a quick round-up
Sunday, 18th October, 2015
[update 20151022: added selectel/pat]
There seem to be three live projects for using SMTP from erlang:
- Richard Carlsson’s sendmail
- the smtp module in Yaws
- Vagabond’s gen_smtp
- Selectel’s pat
** Richard Carlsson’s sendmail
This is a simple-but-useful wrapper round sendmail. Consequently, it depends on the host OS having sendmail up & running. Also consequently, it can take advantage of sendmail’s other features (e.g., retrying failed sends). As Richard explained on erlang-questions in 2011:
Often, what you want is more than just SMTP. If there are some network
issues (or your mail server is simply down) at the time your program
tries to send the mail, you usually want your program to still be able
to regard the mail as sent and carry on. This means that the mail needs
to be persistently stored on disk in a spool area and that the MTA
regularly tries to send any outgoing mail that’s been spooled, so it
will eventually be on its way once the problem is resolved. That’s why
we like to rely on sendmail instead. But it all depends on the needs of
Note: although this is a single script, it is a git repo in its own right, so it can be added as a dependency.
However, as it’s a single-script it doesn’t have anything fancy like a Makefile. I’ve created a fork with a Makefile so I can have it in my erlang.mk Makefile as a dependency: https://github.com/llaisdy/sendmail.
** the smtp module in Yaws
This is a single-script smtp client for sending emails. It does not depend on (or use) sendmail.
It seems that, to add this as a dependency to a project, it would be necessary to either add Yaws itself as a dependency, or manually copy the smtp.erl script into your own project.
** Vagabond’s gen_smtp
This is the full Monty: “a generic Erlang SMTP server framework that can be extended via callback modules in the OTP style. A pure Erlang SMTP client is also included.”
** Selectel’s pat
This connects to a downstream SMTP server to send email messages. An email message is represented by an erlang record.