sending emails with erlang (for use with YXA/CPL)

Joe Armstrong joe@REDACTED
Tue Dec 7 19:26:13 CET 2004


So what's wrong with the stuff in email-1.0? it's pretty easy to 
understand and tweak if it doesn't do what you want. The guts of it do
this:

send(To, Subject, Data) ->
     {TmpFile, S} = open_tmp_file("/tmp", ".mail"),
     io:format(S, "To: <~s>~n", [To]),
     io:format(S, "Subject: ~s~n~n", [Subject]),
     io:format(S, "~s~n",[Data]),
     io:format(S, ".~nquit~n", []),
     close(S),
     io:format("sending ...~n", []),
     unix:cmd("/usr/lib/sendmail -t > /dev/null < " ++ TmpFile),
     delete(TmpFile).

      ... not exactly rocket sience but it does the job

<<I use this code in my wiki to email the user their password
if they forget it :-) >>

     Using a full sntp client or pop3 client for that matter is overkill

    Cheers

/Joe




On Tue, 7 Dec 2004, Administratör wrote:

> Is there some easy way to get erlang to send emails or should I simply use 
> os:cmd/1 and call some appropriate unix command ?
> The only thing I found that might do the job (I haven't looked at it in 
> depth) is email-1.0 by Joe Armstrong, in the erlang.org "User Contributions" 
> section.
>
> I would like to send emails based on mail urls e.g. :
>
>      mailto:jones@REDACTED?subject=Lookup%20failed
>
> i.e. urls that contain a mail address and possibly additional arguments, it 
> should also be possible to attach additional data to the mail in some easy 
> manner.
>
> I'm interested in this as I'm currently implementing CPL (Call Processing 
> Language - RFC 3880), for use with YXA (see 
> http://www.stacken.kth.se/projekt/yxa/) and it would be nice if I could 
> support the CPL mail tag, if it isn't to much work - it's currently a 
> non-essential feature.
>


More information about the erlang-questions mailing list