从erlang发送邮件

nab*_*aib 2 email erlang ubuntu

我在ubuntu 10.10工作,我使用erlang作为语言

我的目标是编写代码以便从erlang发送邮件

我试试这个代码:

-module(mailer).

-compile(export_all).


send(Destination, Subject, Body) ->
    D = string:join(lists:map( fun(Addr) -> binary_to_list(Addr) end, Destination ), " " ),
    S = io_lib:format("~p",[binary_to_list(Subject)]),
    B = io_lib:format("~p",[binary_to_list(Body)]),
    os:cmd("echo "" ++ B ++ "" | mail -s "" ++ S ++ "" " ++ D).
Run Code Online (Sandbox Code Playgroud)

并执行发送功能我尝试:

Erlang R13B03 (erts-5.7.4) [source] [rq:1] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.7.4  (abort with ^G)
1> mailer:send([<<"testFrom@mail.com">>, <<"testto@yahoo.fr">>], <<"hello">>, <<"Hello guys">>..                        
"/bin/sh: mail: not found\n"
Run Code Online (Sandbox Code Playgroud)

如你所见,我有这个错误:

"/bin/sh: mail: not found\n"
Run Code Online (Sandbox Code Playgroud)

Abh*_*ngh 8

我建议在erlang中使用现有的smtp库.gen_smtp是我过去使用过的.发送电子邮件非常简单:

gen_smtp_client:send({"whatever@test.com", ["andrew@hijacked.us"], "Subject: testing\r\nFrom: Andrew Thompson \r\nTo: Some Dude \r\n\r\nThis is the email body"}, [{relay, "smtp.gmail.com"}, {username, "me@gmail.com"}, {password, "mypassword"}]).