2

私は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).

そして、私が試す送信機能を実行するには:

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
4

3 に答える 3

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"}]).

于 2013-01-26T12:15:08.873 に答える
2

お使いのシステムでは「mail」コマンドを使用できないようです。インストール方法については、たとえばこのチュートリアルを参照してください(または自分でグーグルで)。

于 2013-01-26T11:29:24.687 に答える