# HOW-TO sSMTP

## HeXiLeD

What is sSMTP:

DESCRIPTION

 *Quote:*   

> Extremely simple MTA to get mail off the system to a Mailhub
> 
>        ssmtp is a send-only sendmail emulator for machines which normally pick their mail
> 
>        up from a centralized mailhub (via pop, imap, nfs mounts or other means).  It pro-
> ...

 

Starting:

```
# emerge ssmtp

# cd /etc/ssmtp
```

To make things look better when  you recive emails from root  you can edit root's name to something else. However this is completely optional and not needed to make ssmtp work properly.

```
# nano /etc/passwd
```

and change:

```
root:x:0:0:root:/root:/bin/bash
```

to:

```
root:x:0:0:admin:/root:/bin/bash
```

or simply do: 

```
# usermod -c 'admin' root
```

In the following example i will be using rogers.com info to demonstrate how to setup ssmpt

Now lets edit ssmtp.conf.

```
# nano /etc/ssmtp.conf
```

```
# /etc/ssmtp.conf -- a config file for sSMTP sendmail.

# The person who gets all mail for userids < 1000

# Make this empty to disable rewriting.

root=<root@email.address>

# The place where the mail goes. The actual machine name is required

# no MX records are consulted. Commonly mailhosts are named mail.domain.com

# The example will fit if you are in domain.com and your mailhub is so named.

# This should be your remote smtp email server info

mailhub=smtp.broadband.rogers.com

# Example for SMTP port number 2525

# mailhub=mail.your.domain:2525

# Example for SMTP port number 25 (Standard/RFC)

# mailhub=mail.your.domain

# Example for SSL encrypted connection

# mailhub=mail.your.domain:465

# For GMAIL users:  mailhub=gmail.smtp.com:587

# Where will the mail seem to come from?

rewriteDomain=smtp.broadband.rogers.com

# The full hostname

# Gentoo bug #47562

# Commenting the following line will force ssmtp to figure

# out the hostname itself.

# hostname should be your remote email account

hostname=<username>@rogers.com

# auth user must be your remote email username

AuthUser=<username>

# AuthPass must be your remote email password

AuthPass=<password>

# Set this to never rewrite the "From:" line (unless not given) and to

# use that address in the "from line" of the envelope.

FromLineOverride=YES

# Use SSL/TLS to send secure messages to server.

#UseTLS=YES

# With gmail  you should use this option insted of the 'UseTLS=YES'

#UseSTARTTLS=YES

# Use SSL/TLS certificate to authenticate against smtp host.

#UseTLSCert=YES

# Use this RSA certificate.

#TLSCert=/etc/ssl/certs/ssmtp.pem

```

Now we will edit ssmtp/revaliases:

```
# nano /etc/ssmtp/revaliases
```

```
# sSMTP aliases

#

# Format:       local_account:outgoing_address:mailhub

#

# Example: root:your_login@your.domain:mailhub.your.domain[:port]

# where [:port] is an optional port number that defaults to 25.

# with the following example all emails sent from root; when recived

# will show in the from line: From: admin <gentoo@freethinker.net>

# in this case <gentoo> is the box name in  /etc/conf.d/hostname

# and <freethinker.net> the domainame in /etc/resolve.conf

root:gentoo@freethinker.net:smtp.broadband.rogers.com

# if a regular user sends an email without a costumized format then

# then the from line would show: From: john@smtp.broadband.rogers.com 

# if you wish to have your own regular user sending emails with a better 

# looking format like root has, then add something like this for each other user

jack:jack@freethinker.net:smtp.broadband.rogers.com

# what ever you put here <:jack@freethinker.net:> can be costumized

# by your own taste. For a regular user there is no need to change 

# anything in /etc/passwd

```

Testing:

```
# mail -s "testing ssmtp" someguy@some-isp.com

- press enter and you can type whatever you wish as the message body

- press enter and then ctrl+D

- press enter again and the email should be sent 

- check your remote mailbox
```

;EOF

For more details $man ssmtp

sSMTP moves to bssmtp

http://larve.net/people/hugo/2001/02/ssmtp/

update 14/04/2012

http://nixbits.net/wiki/Ssmtp and gmail

----------

## carlosman

I was reviewing the "unanswered posts" list on this forum.  The funny thing is the next item on my to-do list, after answering at least one "unanswered post" was, indeed, searching for info about sSMTP configuration on Gentoo Linux.  After answering my first post I saw your HOWTO.

Talk about instant Karma!!!    :Mr. Green: 

THANK YOU

----------

## dzogi

Thanks for the HOWTO, it has helped me. I'm using gmail's smtp server and it's working as it should   :Cool: 

----------

## jimonade

i've tried various combos including the above as well as from (https://forums.gentoo.org/viewtopic-t-412468-highlight-mutt.html) and i get the following or nothing...

```
mail -s "testing ssmtp" jim@example.com

...

send-mail: Cannot open gmail.smtp.com:587

Can't send mail: sendmail process failed with error code 1
```

any suggestions?  or, could someone post their working (gmail) ssmtp.conf?

----------

## agentgray

I've done everything in this HOWTO, but when I get to the testing phase I get.

```
-bash: mail: command not found
```

I can send a mail using ssmtp as a command.  Could I be missing something somewhere?

----------

## jimonade

what is the output of

```
emerge -vp ssmtp
```

?

----------

## Bobnoxous

I have the same problem. There seems to be no mail command. The output of emerge -vp ssmpt is:

These are the packages that I would merge, in order:

Calculating dependencies ...done!

[ebuild   R   ] mail-mta/ssmtp-2.61  +ipv6 -mailwrapper -md5sum +ssl 0 kB 

I've searched for mail, and it's not on my machine.

> find / -name mail

----------

## Cabal2002

Hi

i have the same problem.

bash: mail: command not found

This prevents my nagios from sending notification mails to me. Anyone any idea how to fix this?

'emerge -vp ssmtp' says

[ebuild   R   ] mail-mta/ssmtp-2.61  +ipv6 -mailwrapper -md5sum +ssl 0 kB

Regards Cabal

----------

## davez

For those who miss the 'mail' command:

```
emerge mailx
```

will do the trick

----------

## cybermatthieu

Hi,

I think your missing a use flag:

```
mailwrapper
```

Add this flag to your /etc/make.conf config file and recompile ssmtp.

Hope it helps,

Matt

----------

## troworld

I'm getting:

```
mail -s "testing ssmtp" myemail

asdlfjhasdfasd

fasdfasdf

Cc:

[<-] 220 smtp103.rog.mail.re2.yahoo.com ESMTP

[->] EHLO myemail

[<-] 250 8BITMIME

Can't send mail: sendmail process failed
```

I have mailx and "emerge -av ssmtp" says:

```
[ebuild   R   ] mail-mta/ssmtp-2.61  USE="ipv6 mailwrapper md5sum ssl"
```

I'm also using rogers, btw.

----------

## Ferdinando

Here I'm using mail-mta/ssmtp-2.61 and I've got no mail command; I simply do

```
/usr/sbin/sendmail user@isp.tld

Subject:test

Hi! :)
```

and I terminate the body with ctrl-D.

Btw Blue-Steel, thanks for the howto, I was trying to find a quick way to set it up, bored of the dead.letter file cron kept creating in /root, and your post was perfect  :Smile: 

Bye

----------

## Tatey

I found this guide and application to be extremely useful. Thanks very much!

----------

## mudrii

Problem is with MTA that require POP before SMTP how can I use sSMTP only for sending mail from the system with POP authentication before sSMTP start sending ?

----------

## OneInchMen

Don't know if this is still helpful:

 *jimonade wrote:*   

> i've tried various combos including the above as well as from (https://forums.gentoo.org/viewtopic-t-412468-highlight-mutt.html) and i get the following or nothing...
> 
> ```
> mail -s "testing ssmtp" jim@example.com
> 
> ...

 

Shouldn't it be: smtp.gmail.com:587 ? instead of the other way around...

----------

## unaos

the method

$echo "mail body" | /usr/sbin/sendmail  -s "test" someone@gmail.com

and i recive empty letter with no subject.

also tried specify recive data from stdin but has the same effect - none.

----------

## Ferdinando

 *unaos wrote:*   

> $echo "mail body" | /usr/sbin/sendmail  -s "test" somone@gmail.com

 

Try

```
$ echo "From:me

To:you

Subject:hi!

how are you?

" | /usr/lib/sendmail someone@someisp
```

I've tried just a moment ago and it worked, though it isn't that elegant, I know...

Bye

----------

## unaos

you rockz dude! that's the classic "RTFM" example - RFC was the answer. shame for me  :Smile: 

and now all is ok with echo -e "Subject: test\n\n the body \n" |  /usr/lib/sendmail somebody@isp.net

----------

## anigel

Hi,

And thanks for this document. I would just suggest a little change here :

 *Blue-Steel wrote:*   

> To make things look better when  you recive emails from root  you can edit root's name to something else. However this is completely optional and not needed to make ssmtp work properly.
> 
> ```
> # nano /etc/passwd
> ```
> ...

 

I think the following command has the same effect ?

```
usermod -c 'admin' root
```

----------

## AssociateX

How do I avoid this:

```

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
```

----------

## ectospasm

It took me weeks to figure this out.  In revaliases, you have this:

```
root:from.addr@domain.tld:mailhub.domain.tld
```

mailhub has to be the mailhub you send through, not the mailhub of the from.addr!  I kept saying,"WTF?  mailhub=mail.mysmtpserver.net in /etc/ssmtp.conf, but it still tries to send through wrong.mailhub.com?  WHY?!?!?!?"  Well, revaliases held the answer.

----------

## accton

Dear Professionals:

Sorry to bother all of you! 

I would like to use SSMTP(ssmtp-2.61) to replace the big "sendmail". In order to use "smtp.gmail.com" to send e-mails, it seems need the SSL support. But there are always compile errors after enabling the SSL option(compile ok without enabling SSL). Should I compile SSMTP by using "Debian" OS?(seems miss the " krb5.h" in my Redhat7 system?) Or something wrong in my compiling procedures as below:

----------- start ----------------------

[wolf@rd-redhat9 ssmtp-2.61]$ ./configure --enable-ssl

loading cache ./config.cache

checking for gcc... (cached) gcc

checking whether the C compiler (gcc  ) works... yes

checking whether the C compiler (gcc  ) is a cross-compiler... no 

checking whether we are using GNU C... (cached) yes

checking whether gcc accepts -g... (cached) yes

checking for a BSD compatible install... (cached) /usr/bin/install -c

checking whether ln -s works... (cached) yes 

checking how to run the C preprocessor... (cached) gcc -E

checking for ANSI C header files... (cached) yes

checking for limits.h... (cached) yes

checking for strings.h... (cached) yes

checking for syslog.h.. . (cached) yes

checking for unistd.h... (cached) yes

checking for obsolete openlog... (cached) no

checking for working const... (cached) yes

checking whether struct tm is in sys/time.h or time.h... (cached) time.h 

checking for gethostname in -lnsl... (cached) yes

checking for socket in -lsocket... (cached) no

checking return type of signal handlers... (cached) void

checking for vprintf... (cached) yes

checking for gethostname... (cached) yes 

checking for socket... (cached) yes

checking for strdup... (cached) yes

checking for strstr... (cached) yes

creating ./config.status

creating Makefile

[wolf@rd-redhat9 ssmtp-2.61]$ make

gcc -Wall  -DSTDC_HEADERS=1 -DHAVE_LIMITS_H=1 -DHAVE_STRINGS_H=1 -DHAVE_SYSLO

=1 -DHAVE_UNISTD_H=1 -DHAVE_LIBNSL=1 -DRETSIGTYPE=void -DHAVE_VPRINTF=1 -DHAV

ETHOSTNAME=1 -DHAVE_SOCKET=1 -DHAVE_STRDUP=1 -DHAVE_STRSTR=1 -DREWRITE_DOMAIN 

-DHAVE_SSL=1  -DSSMTPCONFDIR=\"/usr/local/etc/ssmtp\" -DCONFIGURATION_FILE=\"

r/local/etc/ssmtp/ssmtp.conf\" -DREVALIASES_FILE=\"/usr/local/etc/ssmtp/reval

es\"  -g -O2   -c -o ssmtp.o ssmtp.c

In file included from /usr/include/openssl/ssl.h:179,

                 from ssmtp.c:33:

/usr/include/openssl/kssl.h:73:18: krb5.h: No such file or directory

In file included from /usr/include/openssl/ssl.h:179, 

                 from ssmtp.c:33:

/usr/include/openssl/kssl.h:133: parse error before "krb5_enctype"

/usr/include/openssl/kssl.h:135: parse error before "FAR"

/usr/include/openssl/kssl.h:136: parse error before '}' token 

/usr/include/openssl/kssl.h:148: parse error before "kssl_ctx_setstring"

/usr/include/openssl/kssl.h:148: parse error before '*' token

/usr/include/openssl/kssl.h:149: parse error before '*' token

/usr/include/openssl/kssl.h:150: parse error before '*' token 

/usr/include/openssl/kssl.h:150: parse error before '*' token

/usr/include/openssl/kssl.h:151: parse error before '*' token

/usr/include/openssl/kssl.h:152: parse error before "kssl_ctx_setprinc"

/usr/include/openssl/kssl.h:152: parse error before '*' token 

/usr/include/openssl/kssl.h:154: parse error before "kssl_cget_tkt"

/usr/include/openssl/kssl.h:154: parse error before '*' token

/usr/include/openssl/kssl.h:156: parse error before "kssl_sget_tkt" 

/usr/include/openssl/kssl.h:156: parse error before '*' token

/usr/include/openssl/kssl.h:158: parse error before "kssl_ctx_setkey"

/usr/include/openssl/kssl.h:158: parse error before '*' token

/usr/include/openssl/kssl.h:160: parse error before "context" 

/usr/include/openssl/kssl.h:161: parse error before "kssl_build_principal_2"

/usr/include/openssl/kssl.h:161: parse error before "context"

/usr/include/openssl/kssl.h:164: parse error before "kssl_validate_times" 

/usr/include/openssl/kssl.h:164: parse error before "atime"

/usr/include/openssl/kssl.h:166: parse error before "kssl_check_authent"

/usr/include/openssl/kssl.h:166: parse error before '*' token 

/usr/include/openssl/kssl.h:168: parse error before "enctype"

In file included from ssmtp.c:33:

/usr/include/openssl/ssl.h:909: parse error before "KSSL_CTX"

/usr/include/openssl/ssl.h:931: parse error before '}' token 

make: *** [ssmtp.o] Error 1

------------------ end ---------------------------

Regards,

wolf, Oct-30-2k6

----------

## ectospasm

 *accton wrote:*   

> Dear Professionals:
> 
> Sorry to bother all of you! 
> 
> I would like to use SSMTP(ssmtp-2.61) to replace the big "sendmail". In order to use "smtp.gmail.com" to send e-mails, it seems need the SSL support. But there are always compile errors after enabling the SSL option(compile ok without enabling SSL). Should I compile SSMTP by using "Debian" OS?(seems miss the " krb5.h" in my Redhat7 system?)
> ...

 

This is a Gentoo forum, so I don't know how much help we'll be able to provide a Redhat system.  You probably need to install the devel package for kerberos (kerberos-devel perhaps), assuming of course that krb5.h is part of the kerberos package.  You may need to do some googling to determine what package on your system owns krb5.h.

HTH

----------

## accton

Hi ectospasm:

Thanks! Compile ok after enabling SSL now. Send mail by google SMTP server is successful! 

Thanks for your hint about "kerberos". I copied all missing *.h files(not only krb5.h) from /usr/kerberos/include/ in my Redhat9(sorry! not Redhat7) PC. Then, no compile error. 

****************************************************

Do you know how to cross-compile SSMTP for MIPS CPU board? 

Compile ok after copying the missing *.h files as the above, but link error! The SSL library is missing, I have tried to copy libssl* to my cross-compile directory. But it did not work. The error messages are as below:

-------------- start -----------------

[wolf@rd-redhat9 ssmtp-2.61]$ make

mips-linux-gcc -o ssmtp ssmtp.o arpadate.o base64.o  -lnsl  -lssl

/home/wolf/LSDK-5.0.2.46/tools/gcc-3.3.3-2.4.25/toolchain_mips/lib/gcc-lib/mips-

linux/3.3.3/../../../../mips-linux/bin/ld: skipping incompatible /home/wolf/LSDK

-5.0.2.46/tools/gcc-3.3.3-2.4.25/toolchain_mips/lib/gcc-lib/mips-linux/3.3.3/../

../../../mips-linux/lib/libssl.so when searching for -lssl

/home/wolf/LSDK-5.0.2.46/tools/gcc-3.3.3-2.4.25/toolchain_mips/lib/gcc-lib/mips-

linux/3.3.3/../../../../mips-linux/bin/ld: skipping incompatible /home/wolf/LSDK

-5.0.2.46/tools/gcc-3.3.3-2.4.25/toolchain_mips/lib/gcc-lib/mips-linux/3.3.3/../

../../../mips-linux/lib/libssl.a when searching for -lssl

/home/wolf/LSDK-5.0.2.46/tools/gcc-3.3.3-2.4.25/toolchain_mips/lib/gcc-lib/mips-

linux/3.3.3/../../../../mips-linux/bin/ld: skipping incompatible /home/wolf/LSDK

-5.0.2.46/tools/gcc-3.3.3-2.4.25/toolchain_mips/bin/../lib/libssl.so when search

ing for -lssl

/home/wolf/LSDK-5.0.2.46/tools/gcc-3.3.3-2.4.25/toolchain_mips/lib/gcc-lib/mips-

linux/3.3.3/../../../../mips-linux/bin/ld: skipping incompatible /home/wolf/LSDK

-5.0.2.46/tools/gcc-3.3.3-2.4.25/toolchain_mips/bin/../lib/libssl.a when searchi

ng for -lssl

/home/wolf/LSDK-5.0.2.46/tools/gcc-3.3.3-2.4.25/toolchain_mips/lib/gcc-lib/mips-

linux/3.3.3/../../../../mips-linux/bin/ld: skipping incompatible /home/wolf/LSDK

-5.0.2.46/tools/gcc-3.3.3-2.4.25/toolchain_mips/bin/../../toolchain_mips/lib/lib

ssl.so when searching for -lssl

/home/wolf/LSDK-5.0.2.46/tools/gcc-3.3.3-2.4.25/toolchain_mips/lib/gcc-lib/mips-

linux/3.3.3/../../../../mips-linux/bin/ld: skipping incompatible /home/wolf/LSDK

-5.0.2.46/tools/gcc-3.3.3-2.4.25/toolchain_mips/bin/../../toolchain_mips/lib/lib

ssl.a when searching for -lssl

/home/wolf/LSDK-5.0.2.46/tools/gcc-3.3.3-2.4.25/toolchain_mips/lib/gcc-lib/mips-

linux/3.3.3/../../../../mips-linux/bin/ld: skipping incompatible /home/wolf/LSDK

-5.0.2.46/tools/gcc-3.3.3-2.4.25/toolchain_mips/bin/../../toolchain_mips/usr/lib

/libssl.so when searching for -lssl

/home/wolf/LSDK-5.0.2.46/tools/gcc-3.3.3-2.4.25/toolchain_mips/lib/gcc-lib/mips-

linux/3.3.3/../../../../mips-linux/bin/ld: skipping incompatible /home/wolf/LSDK

-5.0.2.46/tools/gcc-3.3.3-2.4.25/toolchain_mips/bin/../../toolchain_mips/usr/lib

/libssl.a when searching for -lssl

/home/wolf/LSDK-5.0.2.46/tools/gcc-3.3.3-2.4.25/toolchain_mips/lib/gcc-lib/mips-

linux/3.3.3/../../../../mips-linux/bin/ld: cannot find -lssl

collect2: ld returned 1 exit status

make: *** [ssmtp] Error 1

------------- end -----------------------------

Any hint is appreciated!

Regards,

wolf, Oct-31-2k6

----------

## ectospasm

You probably need to cross-compile the libssl package, since an x86 binary library won't work on MIPS.  But cross-compiling is out of my area of expertise, so I don't know how to help you further.

----------

## AsphyX

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:

```

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));

```

----------

## KingOfTheMoles

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

/etc/ssmtp/ssmtp.conf:

```
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:

```
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?

----------

## vesech

 *AssociateX wrote:*   

> How do I avoid this:
> 
> ```
> 
> athlon ~ # mailx root@localhost
> ...

 

I'm having similar issues to this, anybody know how to go about sending local mail?

```

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..

----------

## AsphyX

 *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:

```

# /etc/ssmtp/aliases

gavin@localhost: your_account@domail

gavin: your_account@domain

```

Or just:

```

# /etc/ssmtp/aliases

# "hostname" parameter from ssmtp.conf will be used as domain

gavin@localhost: your_account

gavin: your_account

```

----------

## dogshu

 *AsphyX wrote:*   

> Try to apply my patch (see above)

 

I tried your patch against the ssmtp-2.61 source code, but it fails:

```
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?

----------

## AsphyX

 *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...

```

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

----------

## Vojko

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?

----------

## yesi

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.

----------

## APOAPO

HELLO !!!

THANKS FOR ALL THIS...I NEED ALL

----------

## kdsw1

I'm having this one

```

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

----------

## kdsw1

I have solved my problem. I forgot to emerge mailwrapper.

----------

## jumping

Hi,everybody

How can I  use more than one mailhub in a box?

----------

## Seek

That's what the useflag mailwrapper is used to:

```
seek ~ $ euse -i mailwrapper

global use flags (searching: mailwrapper)

************************************************************

[-    ] mailwrapper - Adds mailwrapper support to allow multiple MTAs to be installed

```

```
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: 

----------

## jumping

thanks Seek.  :Laughing: 

----------

## JeffBlair

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

----------

## zasf

@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

----------

## md5hash

is there a fix in ubuntu?

----------

## lhanson

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?

----------

## donjames

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

----------

## eatnumber1

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.

```
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));
```

----------

## minor_prophets

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

btw-My error was not changing:

```
UseTLS=YES

```

to

```
UseSTARTTLS=YES
```

The latter is correct (for my particular gmail circumstance)

----------

