[erlang-questions] error notification via mail

Adrian Roe roe.adrian@REDACTED
Thu Jul 19 12:38:39 CEST 2012


I've attached 4 files that together form a remarkably simple email sender:

smtp.erl - a very simple SMTP protocol that happily talks to GMail (you 
fill in your account details in the smtp_info record)
smtp.hrl - container for the smtp_info record
mail_sender.erl - not really needed, but an equally simple gen server 
that provides fire and forget access to smtp.erl
i_convert.erl - utility data conversion routines

It's one of the first things I ever wrote in Erlang so it's not pretty, 
but it has been in production for over a year and does appear to "just 
work" (no warranties, feel free to make whatever changes you want, 
please don't sue me...).

Backoff etc (not sending too many emails in too short a time) we have 
always implemented higher up the food chain - we've functions with names 
like "maybe_send_email" that do simple checks as to whether we are 
needlessly filling inboxes with support messages. Those functions are 
just a few lines long and in our case are tightly coupled to the 
business logic that requires the email to be sent so we've never seen 
the point in trying to make that generic.

Feel free to have a play - it should be trivial to get going, but do 
drop me an email if you have any questions.  If you find it useful I 
might even put it up as a simple github project with docs (surely not) 
and an example or two...

Here's how you fill in the record (for GMail).

#smtp_info{
              name = whatever_you_want, %% The name (atom) of the 
gen_server (if you use mail_sender.erl)
              from = <<"your_account@REDACTED">>,
              username = <<"your_account@REDACTED">>,
              password = <<"somev3rysecretthing">>,
              server = <<"smtp.gmail.com">>,
              port = 465}.

To send an email (directly - the gen_server is self explanatory) you

send_mail(SmtpInfo,
           To, %% <<"erlang-questions@REDACTED">>
           ReplyTo, %% Binary - the "from" in the email - should really 
be smtp_info.from
           Subject, %%
           Body,
           Attachments, %% List of attachments to send with the email,
           Type %% text or html).

Read the code - it's simple enough to be documentation for now ;)

Adrian
*Dr Adrian Roe
Director
id3as*

On 19/07/12 09:55, Andrzej Sliwa wrote:
> yep, I just using it … with AirBrake …
> but want to switch to something cost free…
>
> I just testing errbit on heroku - https://github.com/errbit/errbit/
>
> On Jul 19, 2012, at 9:52 AM, Gleb Peregud wrote:
>
>> On Thu, Jul 19, 2012 at 9:49 AM, Max Lapshin <max.lapshin@REDACTED> wrote:
>>> I advise to take a look at hoptoad protocol: there are agents for many
>>> languages.
>> Including Erlang - https://github.com/kenpratt/erlbrake
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120719/d1489bb2/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: i_convert.erl
Type: text/x-erlang
Size: 7301 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120719/d1489bb2/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mail_sender.erl
Type: text/x-erlang
Size: 3577 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120719/d1489bb2/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smtp.erl
Type: text/x-erlang
Size: 4933 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120719/d1489bb2/attachment-0002.bin>
-------------- next part --------------
-record(smtp_info, {name,
		    from,
		    username,
		    password, 
		    server, 
		    port}).


More information about the erlang-questions mailing list