我在ubuntu10.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).
并执行我尝试使用的send函数:
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"
如您所见,我有以下错误:
/bin/sh: mail: not found
3条答案
按热度按时间2q5ifsrm1#
I will recommend using an existing smtp library in erlang. gen_smtp is one that I have used in the past. Sending email is as simple as:
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"}]).
crcmnpdw2#
1 You can try use Sendmail - https://en.wikipedia.org/wiki/Sendmail by Erlang, like here - https://github.com/richcarl/sendmail/blob/master/sendmail.erl
2 You can use https://github.com/Vagabond/gen_smtp
3 You can try implemented simple SMTP client use "smtp.gmail" by RFC https://www.rfc-editor.org/rfc/rfc5321 and try create something like:
More details - http://www.gar1t.com/presentations/2012-07-16-oscon/index.html#slide44
whlutmcx3#
看起来“邮件”命令在您的系统中不可用。请参见eidogg. this tutorial了解如何安装它(或者自己谷歌一个)。