From: Art Cancro Date: Thu, 19 Jan 2006 22:49:55 +0000 (+0000) Subject: * support SMTP-AUTH for outbound connection to smart-host X-Git-Tag: v7.86~4300 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=9c23348bb1751cb4d8d56e034465d63dcf21a41f;p=citadel.git * support SMTP-AUTH for outbound connection to smart-host --- diff --git a/citadel/ChangeLog b/citadel/ChangeLog index a6a27a8e7..220acb244 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,5 +1,8 @@ $Id$ +Thu Jan 19 17:49:29 EST 2006 ajc +* support SMTP-AUTH for outbound connection to smart-host + Thu Jan 19 16:40:57 EST 2006 ajc * Change to journaling code to include an Internet email address for local recipients. diff --git a/citadel/docs/citadel.html b/citadel/docs/citadel.html index 77b5d0ecd..5d8685d96 100644 --- a/citadel/docs/citadel.html +++ b/citadel/docs/citadel.html @@ -1882,9 +1882,13 @@ sites; you may require (due to local convention, security policy, or whatever) that all outbound mail be sent to an SMTP relay or forwarder. To configure this functionality, simply enter the domain name or IP address of your relay -as a 'smart-host' entry. If your relay server is running on a port other +as a 'smart-host' entry.

+

If your relay server is running on a port other than the standard SMTP port 25, you can also specify the port number using "host:port" syntax; i.e. relay99.myisp.com:2525

+

Furthermore, if your relay server requires authentication, you can +specify it using username:password@host or username:password@host:port +syntax; i.e. jsmith:pass123@relay99.myisp.com:25

directory: a domain for which you are participating in directory services across any number of Citadel nodes. For example, if users who have addresses in the domain citadel.org are spread diff --git a/citadel/serv_smtp.c b/citadel/serv_smtp.c index b16d7804f..23a690db8 100644 --- a/citadel/serv_smtp.c +++ b/citadel/serv_smtp.c @@ -942,6 +942,8 @@ void smtp_try(const char *key, const char *addr, int *status, char user[1024], node[1024], name[1024]; char buf[1024]; char mailfrom[1024]; + char mx_user[256]; + char mx_pass[256]; char mx_host[256]; char mx_port[256]; int lp, rp; @@ -1026,11 +1028,23 @@ void smtp_try(const char *key, const char *addr, int *status, sock = (-1); for (mx=0; (mx 1) { + extract_token(mx_user, buf, 0, '@', sizeof mx_user); + if (num_tokens(mx_user, ':') > 1) { + extract_token(mx_pass, mx_user, 1, ':', sizeof mx_pass); + remove_token(mx_user, 1, ':'); + } + remove_token(buf, 0, '@'); + } extract_token(mx_host, buf, 0, ':', sizeof mx_host); extract_token(mx_port, buf, 1, ':', sizeof mx_port); if (!mx_port[0]) { strcpy(mx_port, "25"); } + lprintf(CTDL_DEBUG, "FIXME user<%s> pass<%s> host<%s> port<%s>\n", + mx_user, mx_pass, mx_host, mx_port); lprintf(CTDL_DEBUG, "Trying %s : %s ...\n", mx_host, mx_port); sock = sock_connect(mx_host, mx_port, "tcp"); snprintf(dsn, SIZ, "Could not connect: %s", strerror(errno)); @@ -1088,7 +1102,34 @@ void smtp_try(const char *key, const char *addr, int *status, } } - /* HELO succeeded, now try the MAIL From: command */ + /* Do an AUTH command if necessary */ + if (strlen(mx_user) > 0) { + sprintf(buf, "%s%c%s%c%s%c", mx_user, 0, mx_user, 0, mx_pass, 0); + CtdlEncodeBase64(mailfrom, buf, strlen(mx_user) + strlen(mx_user) + strlen(mx_pass) + 3); + snprintf(buf, sizeof buf, "AUTH PLAIN %s\r\n", mailfrom); + lprintf(CTDL_DEBUG, ">%s", buf); + sock_write(sock, buf, strlen(buf)); + if (ml_sock_gets(sock, buf) < 0) { + *status = 4; + strcpy(dsn, "Connection broken during SMTP AUTH"); + goto bail; + } + lprintf(CTDL_DEBUG, "<%s\n", buf); + if (buf[0] != '2') { + if (buf[0] == '4') { + *status = 4; + safestrncpy(dsn, &buf[4], 1023); + goto bail; + } + else { + *status = 5; + safestrncpy(dsn, &buf[4], 1023); + goto bail; + } + } + } + + /* previous command succeeded, now try the MAIL From: command */ snprintf(buf, sizeof buf, "MAIL From: <%s>\r\n", mailfrom); lprintf(CTDL_DEBUG, ">%s", buf); sock_write(sock, buf, strlen(buf));