Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
HOW-TO sSMTP
View unanswered posts
View posts from last 24 hours

Goto page Previous  1, 2  
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
AsphyX
n00b
n00b


Joined: 25 Jan 2007
Posts: 3

PostPosted: Thu Jan 25, 2007 2:14 pm    Post subject: Reply with quote

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
View user's profile Send private message
KingOfTheMoles
n00b
n00b


Joined: 16 Mar 2004
Posts: 21

PostPosted: Sat Jan 27, 2007 3:52 pm    Post subject: Problem rewriting Reply with quote

I am having a problem rewriting local addresses. I thought all I needed was:

/etc/ssmtp/ssmtp.conf:
Code:
root=me@yahoo.com

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
View user's profile Send private message
vesech
n00b
n00b


Joined: 01 Jun 2006
Posts: 21

PostPosted: Wed Jan 31, 2007 12:17 pm    Post subject: Re: Problem rewriting Reply with quote

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
View user's profile Send private message
AsphyX
n00b
n00b


Joined: 25 Jan 2007
Posts: 3

PostPosted: Wed Jan 31, 2007 1:00 pm    Post subject: Re: Problem rewriting Reply with quote

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
View user's profile Send private message
dogshu
Apprentice
Apprentice


Joined: 22 Jun 2003
Posts: 173
Location: New Haven, CT, USA

PostPosted: Fri Feb 09, 2007 6:33 pm    Post subject: Re: Problem rewriting Reply with quote

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
View user's profile Send private message
AsphyX
n00b
n00b


Joined: 25 Jan 2007
Posts: 3

PostPosted: Mon Feb 12, 2007 8:40 am    Post subject: Re: Problem rewriting Reply with quote

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
View user's profile Send private message
Vojko
n00b
n00b


Joined: 11 Aug 2006
Posts: 27

PostPosted: Mon Mar 26, 2007 9:41 pm    Post subject: Reply with quote

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
View user's profile Send private message
yesi
Guru
Guru


Joined: 25 Oct 2004
Posts: 331

PostPosted: Sat Apr 28, 2007 3:31 pm    Post subject: Reply with quote

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
View user's profile Send private message
APOAPO
n00b
n00b


Joined: 04 May 2007
Posts: 1

PostPosted: Fri May 04, 2007 3:01 am    Post subject: Reply with quote

HELLO !!!

THANKS FOR ALL THIS...I NEED ALL
_________________
Libros Gratis
Foro de Alopecia
Back to top
View user's profile Send private message
kdsw1
n00b
n00b


Joined: 03 Aug 2007
Posts: 9

PostPosted: Fri Aug 03, 2007 1:31 pm    Post subject: Reply with quote

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
View user's profile Send private message
kdsw1
n00b
n00b


Joined: 03 Aug 2007
Posts: 9

PostPosted: Mon Aug 06, 2007 7:32 am    Post subject: Reply with quote

I have solved my problem. I forgot to emerge mailwrapper.
Back to top
View user's profile Send private message
jumping
n00b
n00b


Joined: 21 Aug 2007
Posts: 2

PostPosted: Tue Aug 21, 2007 6:05 am    Post subject: Reply with quote

Hi,everybody
How can I use more than one mailhub in a box?
Back to top
View user's profile Send private message
Seek
n00b
n00b


Joined: 22 Jul 2007
Posts: 47
Location: Austria

PostPosted: Sat Sep 01, 2007 1:31 pm    Post subject: Reply with quote

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.. :wink:
Back to top
View user's profile Send private message
jumping
n00b
n00b


Joined: 21 Aug 2007
Posts: 2

PostPosted: Mon Sep 03, 2007 8:11 am    Post subject: Reply with quote

thanks Seek. :lol:
Back to top
View user's profile Send private message
JeffBlair
Apprentice
Apprentice


Joined: 23 May 2003
Posts: 175
Location: USA, Lone star state

PostPosted: Tue Sep 04, 2007 8:31 pm    Post subject: Reply with quote

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
View user's profile Send private message
zasf
n00b
n00b


Joined: 19 Sep 2007
Posts: 1

PostPosted: Wed Sep 19, 2007 12:13 am    Post subject: aliases patch Reply with quote

@AsphyX: thanks for your nice patch

I opened a bug on launchpad for inclusion in Ubuntu, see
https://bugs.launchpad.net/ubuntu/+source/ssmtp/+bug/140832

Thanks,
Matteo
Back to top
View user's profile Send private message
md5hash
n00b
n00b


Joined: 24 Oct 2007
Posts: 1

PostPosted: Wed Oct 24, 2007 3:18 am    Post subject: Reply with quote

is there a fix in ubuntu?
Back to top
View user's profile Send private message
lhanson
n00b
n00b


Joined: 25 Jul 2007
Posts: 4

PostPosted: Wed Jan 02, 2008 9:30 pm    Post subject: Reply with quote

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
View user's profile Send private message
donjames
Apprentice
Apprentice


Joined: 19 Dec 2004
Posts: 251
Location: 32°9'50" N 94°50'54" W

PostPosted: Fri Feb 29, 2008 6:17 am    Post subject: mailwrapper and ssmtp Reply with quote

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
View user's profile Send private message
eatnumber1
n00b
n00b


Joined: 13 Jan 2007
Posts: 55
Location: New York

PostPosted: Sat Jun 07, 2008 6:58 pm    Post subject: Reply with quote

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
View user's profile Send private message
minor_prophets
Apprentice
Apprentice


Joined: 07 Oct 2007
Posts: 281

PostPosted: Fri Jun 13, 2008 2:23 am    Post subject: Useful Tip Reply with quote

Thank you very much. This was a very useful tip.

btw-My error was not changing:

Code:
UseTLS=YES

to

Code:
UseSTARTTLS=YES

The latter is correct (for my particular gmail circumstance)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
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