2 * smtp.c -- code for speaking SMTP to a listener port
4 * Concept due to Harry Hochheiser. Implementation by ESR. Cleanup and
5 * strict RFC821 compliance by Cameron MacPherson.
7 * Copyright 1996 Eric S. Raymond
9 * For license terms, see the file COPYING in this directory.
14 #include <sys/types.h>
18 #include "fetchmail.h"
21 int smtp_response; /* numeric value of SMTP response code */
23 int SMTP_helo(FILE *sockfp,char *host)
24 /* send a "HELO" message to the SMTP listener */
28 fprintf(sockfp,"HELO %s\r\n", host);
29 if (outlevel == O_VERBOSE)
30 error(0, 0, "SMTP> HELO %s", host);
35 int SMTP_from(FILE *sockfp, char *from)
36 /* send a "MAIL FROM:" message to the SMTP listener */
40 fprintf(sockfp,"MAIL FROM:<%s>\r\n", from);
41 if (outlevel == O_VERBOSE)
42 error(0, 0, "SMTP> MAIL FROM:<%s>", from);
47 int SMTP_rcpt(FILE *sockfp, char *to)
48 /* send a "RCPT TO:" message to the SMTP listener */
52 fprintf(sockfp,"RCPT TO:<%s>\r\n", to);
53 if (outlevel == O_VERBOSE)
54 error(0, 0, "SMTP> RCPT TO:<%s>", to);
59 int SMTP_data(FILE *sockfp)
60 /* send a "DATA" message to the SMTP listener */
64 fprintf(sockfp,"DATA\r\n");
65 if (outlevel == O_VERBOSE)
66 error(0, 0, "SMTP> DATA");
71 int SMTP_quit(FILE *sockfp)
72 /* send a "QUIT" message to the SMTP listener */
76 fprintf(sockfp,"QUIT\r\n");
77 if (outlevel == O_VERBOSE)
78 error(0, 0, "SMTP> QUIT");
83 int SMTP_eom(FILE *sockfp)
84 /* send a message data terminator to the SMTP listener */
88 fprintf(sockfp,".\r\n");
89 if (outlevel == O_VERBOSE)
90 error(0, 0, "SMTP>. (EOM)");
95 int SMTP_ok(FILE *sockfp)
96 /* returns status of SMTP connection */
99 char buf[SMTPBUFSIZE];
101 while ((n = SockGets(buf, sizeof(buf)-1, sockfp)) > 0)
106 if (outlevel == O_VERBOSE)
107 error(0, 0, "SMTP< %s", buf);
108 smtp_response = atoi(buf);
109 if ((buf[0] == '1' || buf[0] == '2' || buf[0] == '3') && buf[3] == ' ')
111 else if (buf[3] != '-')
114 return SM_UNRECOVERABLE;
117 /* smtp.c ends here */