Simple SMTP Sender for Erlang

I've never been able to fathom why SMTP isn't part of the OTP, nor why I can't find a simple third-party SMTP client written in Erlang for sending emails. Anyway, here is a trivial SMTP client for sending emails, hacked together in a few minutes...YMMV.


	-export([send/4, send/5, send/6, send/7]).

	send(To, From, Subject, Message)->
		send(To, From, Subject, Message, Server).

	send(To, From, Subject, Message, Server)->
		send(To, From, Subject, Message, Server, PortNo).

	send(To, From, Subject, Message, Server, PortNo)->
		{ok, Hostname}=inet:gethostname(),
		send(To, From, Subject, Message, Server, PortNo, Hostname).

	send(To, From, Subject, Message, Server, PortNo, LocalDomain)->
		{ok,Sock}=gen_tcp:connect(Server,PortNo,[{active, false}]),
		{ok, "220"++_}=gen_tcp:recv(Sock, 0),
		gen_tcp:send(Sock, lists:append(["HELO ", LocalDomain, [13, 10]])),
		{ok, "250"++_}=gen_tcp:recv(Sock, 0),
		gen_tcp:send(Sock, lists:append(["MAIL FROM: ", From, [13, 10]])),
		{ok, "250"++_}=gen_tcp:recv(Sock, 0),
		gen_tcp:send(Sock, lists:append(["RCPT TO: ", To, [13, 10]])),
		{ok, "250"++_}=gen_tcp:recv(Sock, 0),
		gen_tcp:send(Sock, lists:append(["DATA", [13, 10]])),
		{ok, "354"++_}=gen_tcp:recv(Sock, 0),
		gen_tcp:send(Sock, lists:append(["Subject: ", Subject, [13, 10],[13, 10]])),
		gen_tcp:send(Sock, lists:append([Message])),
		gen_tcp:send(Sock, lists:append([[13, 10],".",[13, 10],[13, 10]])),
		{ok, "250"++_}=gen_tcp:recv(Sock, 0),
		gen_tcp:send(Sock,lists:append("QUIT", [13, 10])),
		{ok, "221"++_}=gen_tcp:recv(Sock, 0),


	Erlang R13B02 (erts-5.7.3) [source] [smp:2:2] [rq:2] [async-threads:0] [kernel-poll:false]

	Eshell V5.7.3  (abort with ^G)
	1> simple_smtp_sender:send("", "", "this is a subject", "and this is a message",  "", 25).