Communicating with SpamAssassin from Erlang

Atilla Erdődi <>
Mon Mar 7 12:27:39 CET 2011

Hi everyone,

I'm trying to use SpamAssassin to check the spam score of a mail from
Erlang using a port.  I've experimented with several options for
open_port, different message formats, but haven't managed to get any
reply from spamc, so it times out. Apparently it doesn't notice the
end of the transmission. Hopefully the solution is something trivial,
I've missed so far.

(The obvious solution would be to reimplement the tcp protocol of
SpamAssassin in Erlang, but I would like simpler solution for now, at
least for the prototype.)

The simplified code is below:

SpamDServer = "",
Exec = os:find_executable("spamc"),
Port = open_port({spawn, Exec ++ " -c -d " ++ SpamDServer}, [use_stdio]),
port_command(Port, "dummy text \r\n"),
port_command(Port, <<4>>), %EOT
    {Port, {data, Res}} ->
        io:format("Spamscore: ~p~n", [Res]);
    Other ->
        io:format("Unknown message: ~p\n", [Other])
after 10000 ->


More information about the erlang-questions mailing list