Skip to content

Latest commit

 

History

History
142 lines (103 loc) · 3.97 KB

README.md

File metadata and controls

142 lines (103 loc) · 3.97 KB

sendmail

Build Status Erlang Versions Tags

Richard Carlsson's sendmail for Erlang, packaged

Contents

Introduction

This is a fork of Richard Carlsson's project, packaged so that it's easily useable in Erlang/LFE release-based projects.

It is based on sendmail.erl by Klacke and smtp.erl by Johan Bevemyr, with code for RFC1522 by Håkan Stenholm. Major cleanup and rewrites by Richard Carlsson. Single argument-as-map support added by Duncan McGreggor (as well as some test and deprecation message cleanups).

Dependencies

  • Erlang must be installed (only versions 19 and above are tested; due to the use of timestamp instead of the deprecated now function, versions of Erlang older than 18 will not be able to use the latest release).
  • sendmail must be installed and is expected to be at /usr/sbin/sendmail.

rebar3 is not expected or required, but this project is structured according to rebar3 project standards.

Features

  • Create email payloads
  • Send messages

Using sendmail

rebar.config

{deps, [
  {sendmail, {git, "https://github.com/erlsci/sendmail", {tag, "0.5.1"}}}
]}.

New API

The new API just uses a map. Create a message:

1> Data = sendmail:create(#{
           to => "[email protected]",
           from => "[email protected]",
           subject => "Hey, Alice!",
           message => "Where's Carol?"}).
["Subject: =?ISO-8859-1?Q?Hey=2C_Alice=21?=\n",
 "From: [email protected]\n","To: [email protected]\n",
 ["Content-Type: text/plain\n",
  "Content-Transfer-Encoding: 8bit\n","\n","Where's Carol?"]]

Send a message:

2> {ExitCode, CmdOutput} = sendmail:send(#{
           to => "[email protected]",
           from => "[email protected]",
           subject => "Hey, Alice!",
           message => "Where's Carol?"}).
{0,[]}

Support for bracketed (RFC 822) email addresses:

2> {ExitCode, CmdOutput} = sendmail:send(#{
           to => "Alice Roberts <[email protected]>",
           from => "Bob Carol <[email protected]>",
           subject => "Hey, Alice!",
           message => "Where's Carol?"}).
{0,[]}

Old API

Create a payload:

3> Data = sendmail:create("[email protected]", "[email protected]", "Hey, Alice!",
      "Where's Carol?").
["Subject: =?ISO-8859-1?Q?Hey=2C_Alice=21?=\n",
 "From: [email protected]\n","To: [email protected]\n",
 ["Content-Type: text/plain\n",
  "Content-Transfer-Encoding: 8bit\n","\n","Where's Carol?"]]

Send a message directly:

4> {ExitCode, CmdOutput} = sendmail:send("[email protected]", "[email protected]",
      "Hey, Alice!", "Where's Carol?").
{0,[]}

License

BSD 3-Clause License

Copyright © 2004, Johan Bevemyr

Copyright © 2005, Klacke [email protected]

Copyright © 2009, Håkan Stenholm

Copyright © 2009, Richard Carlsson

Copyright © 2020, Duncan McGreggor