bb02cc | 1997-09-15 | Fredrik Hübinette (Hubbe) | | class protocol
{
|
5946a2 | 1998-04-29 | Fredrik Noring | | inherit .NNTP.protocol;
|
bb02cc | 1997-09-15 | Fredrik Hübinette (Hubbe) | | }
class client
{
inherit protocol;
|
cc1c0e | 1998-03-07 | Fredrik Noring | | constant reply_codes =
([ 211:"System status, or system help reply",
214:"Help message",
220:"<host> Service ready",
221:"<host> Service closing transmission channel",
250:"Requested mail action okay, completed",
251:"User not local; will forward to <forward-path>",
354:"Start mail input; end with <CRLF>.<CRLF>",
421:"<host> Service not available, closing transmission channel "
"[This may be a reply to any command if the service knows it "
"must shut down]",
450:"Requested mail action not taken: mailbox unavailable "
"[E.g., mailbox busy]",
451:"Requested action aborted: local error in processing",
452:"Requested action not taken: insufficient system storage",
500:"Syntax error, command unrecognized "
"[This may include errors such as command line too long]",
501:"Syntax error in parameters or arguments",
502:"Command not implemented",
503:"Bad sequence of commands",
504:"Command parameter not implemented",
550:"Requested action not taken: mailbox unavailable "
"[E.g., mailbox not found, no access]",
551:"User not local; please try <forward-path>",
552:"Requested mail action aborted: exceeded storage allocation",
553:"Requested action not taken: mailbox name not allowed "
"[E.g., mailbox syntax incorrect]",
554:"Transaction failed" ]);
static private int cmd(string c, string|void comment)
{
int r = command(c);
switch(r) {
case 200..399:
break;
default:
throw(({"SMTP: "+c+"\n"+(comment?"SMTP: "+comment+"\n":"")+
"SMTP: "+reply_codes[r]+"\n", backtrace()}));
}
return r;
}
|
98fe34 | 1998-05-26 | David Hedbor | | void create(void|string server, int|void port)
|
bb02cc | 1997-09-15 | Fredrik Hübinette (Hubbe) | | {
if(!server)
{
object dns=master()->resolv("Protocols")["DNS"]->client();
server=dns->get_primary_mx(gethostname());
}
|
98fe34 | 1998-05-26 | David Hedbor | | if(!port)
port = 25;
|
c93635 | 1999-06-02 | Fredrik Noring | | if(!server || !connect(server, port))
|
bb02cc | 1997-09-15 | Fredrik Hübinette (Hubbe) | | {
|
5fcb23 | 1998-04-19 | Niels Möller | | throw(({"Failed to connect to mail server.\n",backtrace()}));
|
bb02cc | 1997-09-15 | Fredrik Hübinette (Hubbe) | | }
if(readreturncode()/100 != 2)
throw(({"Connection refused by SMTP server.\n",backtrace()}));
|
cc1c0e | 1998-03-07 | Fredrik Noring | | if(catch(cmd("EHLO "+gethostname())))
cmd("HELO "+gethostname(), "greeting failed.");
}
void send_message(string from, string *to, string body)
{
|
5fcb23 | 1998-04-19 | Niels Möller | | cmd("MAIL FROM: "+from);
|
cc1c0e | 1998-03-07 | Fredrik Noring | | foreach(to, string t)
|
5fcb23 | 1998-04-19 | Niels Möller | | cmd("RCPT TO: "+t);
|
cc1c0e | 1998-03-07 | Fredrik Noring | | cmd("DATA");
cmd(body+"\r\n.");
cmd("QUIT");
|
bb02cc | 1997-09-15 | Fredrik Hübinette (Hubbe) | | }
|
cc1c0e | 1998-03-07 | Fredrik Noring | | void simple_mail(string to, string subject, string from, string msg)
|
bb02cc | 1997-09-15 | Fredrik Hübinette (Hubbe) | | {
|
cc1c0e | 1998-03-07 | Fredrik Noring | | send_message(from, ({ to }),
|
baa6a6 | 1998-05-12 | Marcus Comstedt | | (string)MIME.Message(msg, (["mime-version":"1.0",
"subject":subject,
"from":from,
"to":to,
"content-type":
"text/plain;charset=iso-8859-1",
"content-transfer-encoding":
"8bit"])));
|
bb02cc | 1997-09-15 | Fredrik Hübinette (Hubbe) | | }
}
|