View previous topic :: View next topic |
Author |
Message |
AsphyX n00b
Joined: 25 Jan 2007 Posts: 3
|
Posted: Thu Jan 25, 2007 2:14 pm Post subject: |
|
|
I have add a support of simple aliases to ssmtp. Substitution occur when sending "RCPT TO" to server, but before all other substitutions (UID checking, appending domain etc.). It means if I remap "eugene" to "root", message will be sent to address, specified if "root" option in ssmtp.conf. Look at this patch:
Code: |
diff -r -u -N ssmtp-2.61/aliases ssmtp-2.61.new/aliases
--- ssmtp-2.61/aliases 1970-01-01 03:00:00.000000000 +0300
+++ ssmtp-2.61.new/aliases 2007-01-25 13:06:28.000000000 +0300
@@ -0,0 +1,5 @@
+# Simple rcpt aliases
+# Mapping done before all other translations (UID checking, appending domain, etc.)
+#
+# Example:
+# john: john.smith@domain.com
diff -r -u -N ssmtp-2.61/Makefile.in ssmtp-2.61.new/Makefile.in
--- ssmtp-2.61/Makefile.in 2004-07-26 09:32:18.000000000 +0400
+++ ssmtp-2.61.new/Makefile.in 2007-01-25 13:02:50.000000000 +0300
@@ -17,9 +17,11 @@
# Configuration files
CONFIGURATION_FILE=$(SSMTPCONFDIR)/ssmtp.conf
REVALIASES_FILE=$(SSMTPCONFDIR)/revaliases
+ALIASES_FILE=$(SSMTPCONFDIR)/aliases
INSTALLED_CONFIGURATION_FILE=$(CONFIGURATION_FILE)
INSTALLED_REVALIASES_FILE=$(REVALIASES_FILE)
+INSTALLED_ALIASES_FILE=$(ALIASES_FILE)
# Programs
GEN_CONFIG=$(srcdir)/generate_config
@@ -34,6 +36,7 @@
-DSSMTPCONFDIR=\"$(SSMTPCONFDIR)\" \
-DCONFIGURATION_FILE=\"$(CONFIGURATION_FILE)\" \
-DREVALIASES_FILE=\"$(REVALIASES_FILE)\" \
+-DALIASES_FILE=\"$(ALIASES_FILE)\" \
CFLAGS=-Wall @DEFS@ $(EXTRADEFS) @CFLAGS@
@@ -52,6 +55,7 @@
$(INSTALL) -m 644 $(srcdir)/ssmtp.8 $(mandir)/ssmtp.8
$(INSTALL) -d -m 755 $(SSMTPCONFDIR)
$(INSTALL) -m 644 $(srcdir)/revaliases $(INSTALLED_REVALIASES_FILE)
+ $(INSTALL) -m 644 $(srcdir)/aliases $(INSTALLED_ALIASES_FILE)
$(GEN_CONFIG) $(INSTALLED_CONFIGURATION_FILE)
@@ -69,7 +73,7 @@
uninstall:
$(RM) $(bindir)/ssmtp
$(RM) $(mandir)/ssmtp.8
- $(RM) $(CONFIGURATION_FILE) $(REVALIASES_FILE)
+ $(RM) $(CONFIGURATION_FILE) $(REVALIASES_FILE) $(ALIASES_FILE)
$(RM) -r $(SSMTPCONFDIR)
.PHONY: uninstall-sendmail
diff -r -u -N ssmtp-2.61/ssmtp.c ssmtp-2.61.new/ssmtp.c
--- ssmtp-2.61/ssmtp.c 2004-07-23 09:58:48.000000000 +0400
+++ ssmtp-2.61.new/ssmtp.c 2007-01-25 15:53:15.000000000 +0300
@@ -420,6 +420,46 @@
}
/*
+ * Eugene:
+ *
+ * simple aliases support:
+ * lookup aliases file and remap rcpt
+ */
+char *aliases_lookup(char *str)
+{
+ char buf[(BUF_SZ + 1)], *p;
+ char name[(BUF_SZ + 1)];
+ FILE *fp;
+ char *saveptr = NULL;
+
+ if((fp = fopen(ALIASES_FILE, "r"))) {
+ strncpy(name, str, BUF_SZ);
+ while(fgets(buf, sizeof(buf), fp)) {
+ /* Make comments invisible */
+ if((p = strchr(buf, '#'))) {
+ *p = (char)NULL;
+ }
+
+ /* Ignore malformed lines and comments */
+ if(strchr(buf, ':') == (char *)NULL) {
+ continue;
+ }
+
+ /* Parse the alias */
+ if( (p = strtok_r(buf, ": \t\r\n", &saveptr) ) && !strncmp(p, name, BUF_SZ) &&
+ (p = strtok_r(NULL, ": \t\r\n", &saveptr) )) {
+ /*if(log_level > 0)*/ log_event(LOG_INFO, "Remapping: \"%s\" --> \"%s\"\n", name, p);
+ strncpy(name, p, BUF_SZ);
+ }
+ }
+
+ fclose(fp);
+ return strdup(name);
+
+ } else return str; /* can't read aliases? it's not a problem */
+}
+
+/*
from_strip() -- Transforms "Name <login@host>" into "login@host" or "login@host (Real name)"
*/
char *from_strip(char *str)
@@ -480,6 +520,11 @@
die("from_format() -- snprintf() failed");
}
}
+ else {
+ if(snprintf(buf, BUF_SZ, "%s", str) == -1) {
+ die("from_format() -- snprintf() failed");
+ }
+ }
}
#if 0
@@ -640,9 +685,14 @@
char *rcpt_remap(char *str)
{
struct passwd *pw;
- if((root==NULL) || strlen(root)==0 || strchr(str, '@') ||
- ((pw = getpwnam(str)) == NULL) || (pw->pw_uid > MAXSYSUID)) {
- return(append_domain(str)); /* It's not a local systems-level user */
+ char *rcpt;
+
+ /* before all other mappings */
+ rcpt = aliases_lookup(str);
+
+ if((root==NULL) || strlen(root)==0 || strchr(rcpt, '@') ||
+ ((pw = getpwnam(rcpt)) == NULL) || (pw->pw_uid > MAXSYSUID)) {
+ return(append_domain(rcpt)); /* It's not a local systems-level user */
}
else {
return(append_domain(root));
|
|
|
Back to top |
|
|
KingOfTheMoles n00b
Joined: 16 Mar 2004 Posts: 21
|
Posted: Sat Jan 27, 2007 3:52 pm Post subject: Problem rewriting |
|
|
I am having a problem rewriting local addresses. I thought all I needed was:
/etc/ssmtp/ssmtp.conf:
to make something like this work:
mail -v -s "ssmtp test" root
But it doesn't rewrite the envelope, which I think is what I need. Here is debug:
Code: | Lestat bin# mail -v -s "ssmtp test" root
.
Cc:
Null message body; hope that's ok
[<-] 220 equipment to accept, transmit, or distribute unsolicited e-mail.
<SNIP>
[<-] 235 Authentication succeeded
[->] MAIL FROM:<me@yahoo.com>
[<-] 250 OK
[->] RCPT TO:<me@yahoo.com>
[<-] 250 Accepted
[->] DATA
[<-] 354 Enter message, ending with "." on a line by itself
[->] Received: by me@yahoo.com (sSMTP sendmail emulation); Sat, 27 Jan 2007 10:49:45 -0500
[->] From: "root" <me@yahoo.com>
[->] Date: Sat, 27 Jan 2007 10:49:45 -0500
[->] To: root
[->] Subject: ssmtp test
[->]
[->] .
[<-] 550 Your message does not conform to RFC2822 standard
send-mail: 550 Your message does not conform to RFC2822 standard
Can't send mail: sendmail process failed with error code 1
|
Note the RCPT gets rewritten, but not the "To:"
Any ideas? |
|
Back to top |
|
|
vesech n00b
Joined: 01 Jun 2006 Posts: 21
|
Posted: Wed Jan 31, 2007 12:17 pm Post subject: Re: Problem rewriting |
|
|
AssociateX wrote: | How do I avoid this:
Code: |
athlon ~ # mailx root@localhost
Subject: test
test.
Cc: send-mail: Cannot open localhost:25
Can't send mail: sendmail process failed with error code 1 |
|
I'm having similar issues to this, anybody know how to go about sending local mail?
Code: |
sokar:~% echo 'hi' | mailx -s 'test' gavin@localhost
send-mail: RCPT TO:<gavin@localhost> (553 Invalid address syntax)
Can't send mail: sendmail process failed with error code 1
|
I've ssmtp set up and configured, and I think mailx is using that instead and thus trying all the isp server stuff (which should be unneeded for local addresses). Sending remote email is working fine, though.. |
|
Back to top |
|
|
AsphyX n00b
Joined: 25 Jan 2007 Posts: 3
|
Posted: Wed Jan 31, 2007 1:00 pm Post subject: Re: Problem rewriting |
|
|
vesech wrote: |
I'm having similar issues to this, anybody know how to go about sending local mail?
|
I have found only one solution for this: adding aliases support to ssmtp. Otherwise ssmtp will try to send all messages for local users with uid>999 to username@hostname, where "username" is name, cpecified in mail/mailx command line. Try to apply my patch (see above) and write such aliases:
Code: |
# /etc/ssmtp/aliases
gavin@localhost: your_account@domail
gavin: your_account@domain
|
Or just:
Code: |
# /etc/ssmtp/aliases
# "hostname" parameter from ssmtp.conf will be used as domain
gavin@localhost: your_account
gavin: your_account
|
|
|
Back to top |
|
|
dogshu Apprentice
Joined: 22 Jun 2003 Posts: 173 Location: New Haven, CT, USA
|
Posted: Fri Feb 09, 2007 6:33 pm Post subject: Re: Problem rewriting |
|
|
AsphyX wrote: | Try to apply my patch (see above) |
I tried your patch against the ssmtp-2.61 source code, but it fails:
Code: | delta-9 ssmtp-2.61 # cat ssmtp-aliases.patch | patch -p1
patching file aliases
patching file Makefile.in
Hunk #3 FAILED at 55.
Hunk #4 FAILED at 73.
2 out of 4 hunks FAILED -- saving rejects to file Makefile.in.rej
patching file ssmtp.c
Hunk #1 FAILED at 420.
Hunk #2 FAILED at 520.
Hunk #3 FAILED at 685.
3 out of 3 hunks FAILED -- saving rejects to file ssmtp.c.rej
delta-9 ssmtp-2.61 # |
Any idea what I'm doing wrong? |
|
Back to top |
|
|
AsphyX n00b
Joined: 25 Jan 2007 Posts: 3
|
Posted: Mon Feb 12, 2007 8:40 am Post subject: Re: Problem rewriting |
|
|
dogshu wrote: | AsphyX wrote: | Try to apply my patch (see above) |
I tried your patch against the ssmtp-2.61 source code, but it fails:
Any idea what I'm doing wrong? |
Hmmm...
Code: |
asphyx@coffecup ~/tmp/ssmtp/ssmtp-2.61 $ patch -p1 < ../ssmtp-2.61-aliases.patch
patching file aliases
patching file Makefile.in
patching file ssmtp.c
|
All ok...
ssmtp sources found in Gentoo distfiles (ssmtp_2.61.orig.tar.gz)
Try to download patch here: http://lord-asphyx.narod.ru/ssmtp-2.61-aliases.patch.gz |
|
Back to top |
|
|
Vojko n00b
Joined: 11 Aug 2006 Posts: 27
|
Posted: Mon Mar 26, 2007 9:41 pm Post subject: |
|
|
ok after about 3h of emerging and configuring i finally got ssmtp working (nice guide btw) to send mail through my gmail account. but now i have a question
Sudo sends mail to email address root by default and because this mail address (hopefully or else someone is going to have a good laugh at gmail) doesn't exists it goes nowhere. I found out if you put Defaults mailto=user@email.somewhere into /etc/sudoers file sudo sends it to that email address. But now i'm wondering if you could set ssmtp that way if user sends mail to root (for example sendmail root ... bla bla bla ctrl+d) it would get redirected to user@email.somewhere. Is that possible? |
|
Back to top |
|
|
yesi Guru
Joined: 25 Oct 2004 Posts: 331
|
Posted: Sat Apr 28, 2007 3:31 pm Post subject: |
|
|
and if you have not a "domain name"...
it's just a desktop but i need a smtp server for the need of a script...
i'd like to use smtp.gmail.com:465 with ssl to send ...
what do you think about the configuration?
thank in advance. |
|
Back to top |
|
|
APOAPO n00b
Joined: 04 May 2007 Posts: 1
|
|
Back to top |
|
|
kdsw1 n00b
Joined: 03 Aug 2007 Posts: 9
|
Posted: Fri Aug 03, 2007 1:31 pm Post subject: |
|
|
I'm having this one
Code: |
tux / # mail -s "dd" xxx@xxx.xx
dd
Cc:
mail: /usr/sbin/sendmail: No such file or directory
Can't send mail: sendmail process failed
tux / #
|
I have ssmtp installed with mailwrapper and also I have just installed mailx
I think I haven't run some daemon?
Please help me |
|
Back to top |
|
|
kdsw1 n00b
Joined: 03 Aug 2007 Posts: 9
|
Posted: Mon Aug 06, 2007 7:32 am Post subject: |
|
|
I have solved my problem. I forgot to emerge mailwrapper. |
|
Back to top |
|
|
jumping n00b
Joined: 21 Aug 2007 Posts: 2
|
Posted: Tue Aug 21, 2007 6:05 am Post subject: |
|
|
Hi,everybody
How can I use more than one mailhub in a box? |
|
Back to top |
|
|
Seek n00b
Joined: 22 Jul 2007 Posts: 47 Location: Austria
|
Posted: Sat Sep 01, 2007 1:31 pm Post subject: |
|
|
That's what the useflag mailwrapper is used to:
Code: | seek ~ $ euse -i mailwrapper
global use flags (searching: mailwrapper)
************************************************************
[- ] mailwrapper - Adds mailwrapper support to allow multiple MTAs to be installed
|
Code: | seek ~ $ emerge sendmail -pv
[ebuild N ] mail-filter/procmail-3.22-r7 USE="-mbox (-selinux)" 222 kB
[ebuild N ] mail-mta/sendmail-8.14.0 USE="ipv6 ssl tcpd -ldap -mailwrapper -mbox -nis -sasl -sockets" 2,009 kB
[blocks B ] mail-mta/ssmtp (is blocking mail-mta/sendmail-8.14.0)
seek ~ $ USE="mailwrapper" emerge sendmail -pv
[ebuild N ] net-mail/mailwrapper-0.2.1 7 kB
[ebuild N ] mail-filter/procmail-3.22-r7 USE="-mbox (-selinux)" 222 kB
[ebuild N ] mail-mta/sendmail-8.14.0 USE="ipv6 mailwrapper ssl tcpd -ldap -mbox -nis -sasl -sockets" 2,009 kB
|
You see.. |
|
Back to top |
|
|
jumping n00b
Joined: 21 Aug 2007 Posts: 2
|
Posted: Mon Sep 03, 2007 8:11 am Post subject: |
|
|
thanks Seek. |
|
Back to top |
|
|
JeffBlair Apprentice
Joined: 23 May 2003 Posts: 175 Location: USA, Lone star state
|
Posted: Tue Sep 04, 2007 8:31 pm Post subject: |
|
|
OK, just call me a bone head. If I emerge this, how would I tell Postfix to use this.
I just changed my provider, and they use SSL SMTP servers, so I figured I would use gmails.
Thanks |
|
Back to top |
|
|
zasf n00b
Joined: 19 Sep 2007 Posts: 1
|
|
Back to top |
|
|
md5hash n00b
Joined: 24 Oct 2007 Posts: 1
|
Posted: Wed Oct 24, 2007 3:18 am Post subject: |
|
|
is there a fix in ubuntu? |
|
Back to top |
|
|
lhanson n00b
Joined: 25 Jul 2007 Posts: 4
|
Posted: Wed Jan 02, 2008 9:30 pm Post subject: |
|
|
I installed AsphyX's patch (thanks for the good work, btw) but found that Google still wasn't delivering my mail addressed to a local user because though the "RCPT TO:" line was correctly remapped from the local username to the gmail alias, the "To: " line in the DATA section was not remapped and still read "root", for example. I modified ssmtp.c further to perform the same aliasing in the To: line of the DATA section, and now it works great.
Has this been submitted for inclusion into the sSMTP ebuild? In the meantime, maybe we can create an overlay package? |
|
Back to top |
|
|
donjames Apprentice
Joined: 19 Dec 2004 Posts: 251 Location: 32°9'50" N 94°50'54" W
|
Posted: Fri Feb 29, 2008 6:17 am Post subject: mailwrapper and ssmtp |
|
|
Hi folks,
I've been going nuts trying to get ssmtp to work.
Well, after spending several hours reading the forums on ssmtp, I finally realized that I HAD NOT emerged mailwrapper.
DUH!!
Hope this helps someone.
Sincerely,
Don James |
|
Back to top |
|
|
eatnumber1 n00b
Joined: 13 Jan 2007 Posts: 55 Location: New York
|
Posted: Sat Jun 07, 2008 6:58 pm Post subject: |
|
|
I modified AsphyX's patch so that it supports more than one level of aliasing (you can now alias postmaster: root, and root: myemail@gmail.com) (it's now recursive ^_^). I also changed it to use the aliases file installed by mailbase.
Code: | diff -u -r -N ssmtp-2.61/Makefile.in ssmtp-2.61.new/Makefile.in
--- ssmtp-2.61/Makefile.in 2008-06-07 14:41:15.000000000 -0400
+++ ssmtp-2.61.new/Makefile.in 2008-06-07 14:41:46.000000000 -0400
@@ -17,9 +17,11 @@
# Configuration files
CONFIGURATION_FILE=$(SSMTPCONFDIR)/ssmtp.conf
REVALIASES_FILE=$(SSMTPCONFDIR)/revaliases
+ALIASES_FILE=/etc/mail/aliases
INSTALLED_CONFIGURATION_FILE=$(CONFIGURATION_FILE)
INSTALLED_REVALIASES_FILE=$(REVALIASES_FILE)
+INSTALLED_ALIASES_FILE=$(ALIASES_FILE)
# Programs
GEN_CONFIG=$(srcdir)/generate_config
@@ -34,6 +36,7 @@
-DSSMTPCONFDIR=\"$(SSMTPCONFDIR)\" \
-DCONFIGURATION_FILE=\"$(CONFIGURATION_FILE)\" \
-DREVALIASES_FILE=\"$(REVALIASES_FILE)\" \
+-DALIASES_FILE=\"$(ALIASES_FILE)\" \
CFLAGS=-Wall @DEFS@ $(EXTRADEFS) @CFLAGS@
@@ -52,6 +55,7 @@
$(INSTALL) -m 644 $(srcdir)/ssmtp.8 $(mandir)/ssmtp.8
$(INSTALL) -d -m 755 $(SSMTPCONFDIR)
$(INSTALL) -m 644 $(srcdir)/revaliases $(INSTALLED_REVALIASES_FILE)
+ $(INSTALL) -m 644 $(srcdir)/aliases $(INSTALLED_ALIASES_FILE)
$(GEN_CONFIG) $(INSTALLED_CONFIGURATION_FILE)
@@ -69,7 +73,7 @@
uninstall:
$(RM) $(bindir)/ssmtp
$(RM) $(mandir)/ssmtp.8
- $(RM) $(CONFIGURATION_FILE) $(REVALIASES_FILE)
+ $(RM) $(CONFIGURATION_FILE) $(REVALIASES_FILE) $(ALIASES_FILE)
$(RM) -r $(SSMTPCONFDIR)
.PHONY: uninstall-sendmail
diff -u -r -N ssmtp-2.61/ssmtp.c ssmtp-2.61.new/ssmtp.c
--- ssmtp-2.61/ssmtp.c 2008-06-07 14:41:15.000000000 -0400
+++ ssmtp-2.61.new/ssmtp.c 2008-06-07 14:41:51.000000000 -0400
@@ -420,7 +420,52 @@
}
/*
+ * Eugene:
+ *
+ * simple aliases support:
+ * lookup aliases file and remap rcpt
+ */
+char *aliases_lookup(char *str)
+{
+ char buf[(BUF_SZ + 1)], *p;
+ char name[(BUF_SZ + 1)];
+ FILE *fp;
+ char *saveptr = NULL;
+
+ if((fp = fopen(ALIASES_FILE, "r"))) {
+ strncpy(name, str, BUF_SZ);
+ while(fgets(buf, sizeof(buf), fp)) {
+ /* Make comments invisible */
+ if((p = strchr(buf, '#'))) {
+ *p = (char)NULL;
+ }
+
+ /* Ignore malformed lines and comments */
+ if(strchr(buf, ':') == (char *)NULL) {
+ continue;
+ }
+
+ /* Parse the alias */
+ if( (p = strtok_r(buf, ": \t\r\n", &saveptr) ) && !strncmp(p, name, BUF_SZ) &&
+ (p = strtok_r(NULL, ": \t\r\n", &saveptr) )) {
+ /*if(log_level > 0)*/ log_event(LOG_INFO, "Remapping: \"%s\" --> \"%s\"\n", name, p);
+ strncpy(name, p, BUF_SZ);
+ }
+ }
+
+ fclose(fp);
+ if( strcmp( str, name ) == 0 ) {
+ return strdup(name);
+ } else {
+ return aliases_lookup(name);
+ }
+
+ } else return str; /* can't read aliases? it's not a problem */
+}
+
+/*
from_strip() -- Transforms "Name <login@host>" into "login@host" or "login@host (Real name)"
+
*/
char *from_strip(char *str)
{
@@ -645,9 +690,14 @@
char *rcpt_remap(char *str)
{
struct passwd *pw;
- if((root==NULL) || strlen(root)==0 || strchr(str, '@') ||
- ((pw = getpwnam(str)) == NULL) || (pw->pw_uid > MAXSYSUID)) {
- return(append_domain(str)); /* It's not a local systems-level user */
+ char *rcpt;
+
+ /* before all other mappings */
+ rcpt = aliases_lookup(str);
+
+ if((root==NULL) || strlen(root)==0 || strchr(rcpt, '@') ||
+ ((pw = getpwnam(rcpt)) == NULL) || (pw->pw_uid > MAXSYSUID)) {
+ return(append_domain(rcpt)); /* It's not a local systems-level user */
}
else {
return(append_domain(root)); |
|
|
Back to top |
|
|
minor_prophets Apprentice
Joined: 07 Oct 2007 Posts: 281
|
Posted: Fri Jun 13, 2008 2:23 am Post subject: Useful Tip |
|
|
Thank you very much. This was a very useful tip.
btw-My error was not changing:
to
The latter is correct (for my particular gmail circumstance) |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|