NullLogic

...

#!/usr/bin/nsp function send_mail(msg, host, port) { local function swrite(sock, text) { print(text); return sock.write(text); } local function sread(sock) { in=sock.gets(); if (typeof(in)!='string') throw "sock.gets() input error"; print(in+"\n"); return in; } /* * most smtp clients at least pretend to check for errors, but not this one... */ if (host==null) host='localhost'; if (port==null) port=25; sock=new net.tcp.socket(); sock.connect(host, port, false); if (typeof(sock.socket)!='sock4') { print("can't connect to smtp server\n"); return; } sread(sock); swrite(sock, "HELO <localhost>\r\n"); sread(sock); swrite(sock, "MAIL From: <"+msg.from+">\r\n"); sread(sock); swrite(sock, "RCPT To: <"+msg.to+">\r\n"); sread(sock); swrite(sock, "DATA\r\n"); sread(sock); swrite(sock, "From: "+msg.from+"\r\n"); swrite(sock, "To: "+msg.to+"\r\n"); swrite(sock, "Subject: "+msg.subject+"\r\n"); swrite(sock, "\r\n"); swrite(sock, ""+msg.body+"\r\n"); swrite(sock, ".\r\n"); sread(sock); swrite(sock, "QUIT\r\n"); sread(sock); if (typeof(sock.socket)=='sock4') sock.close(); delete sock; return; } //send_mail({from="me@here.com";to="you@there.com";subject="test";body="test body";});