OpenWrt Forum Archive

Topic: [Howto] Sending Mails from OpenWrt

The content of this topic has been archived on 6 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Sending Mails from OpenWrt

Describes how to send Mails from OpenWrt using the ssmtp program.

1. Install the ssmtp package (depends on libopenssl)

ipkg install ssmtp

2. Change /etc/ssmtp/ssmtp.conf. For GMX I've to change the following lines:

root=<secret>@gmx.net
mailhub=mail.gmx.net
hostname=gmx.de
FromLineOverride=YES
AuthUser=secret@gmx.de
AuthPass=<password>

3. Create a Mail and save it in /test-email.txt

From: <secret@gmx.de>
To: <secret@gmx.de>
Subject: The subject

The body...

4. Finally send the Mail

cat test-email.txt | ssmtp -v secret@gmx.de
[<-] 220 mail.gmx.net GMX Mailservices ESMTP {mp042}
[->] EHLO gmx.de
[<-] 250 STARTTLS
[->] AUTH LOGIN XXXXXXXXXXXX
[<-] 334 XXXXXXXXXXXX
[->] XXXXXXXXXXXX
[<-] 235 2.7.0 Go ahead {mp042}
[->] MAIL FROM:<secret@gmx.de>
[<-] 250 2.1.0 ok {mp042}
[->] RCPT TO:<secret@gmx.de>
[<-] 250 2.1.5 ok {mp042}
[->] DATA
[<-] 354 mail.gmx.net Go ahead {mp042}
[->] Received: by gmx.de (sSMTP sendmail emulation); Thu, 30 Aug 2007 20:37:26 +0200
[->] Date: Thu, 30 Aug 2007 20:37:26 +0200
[->] From: <secret@gmx.de>
[->] To: <secret@gmx.de>
[->] Subject: The subject
[->] 
[->] The body...
[->] 
[->] .
[<-] 250 2.6.0 Message accepted {mp042}
[->] QUIT
[<-] 221 2.0.0 GMX Mailservices {mp042}

(Last edited by forum2006 on 30 Aug 2007, 21:00)

I can't figure this out, and any input would really help.

I rsync my backups offsite every night. I decided to follow http://wiki.openwrt.org/rsync-usb-sambaHowTo it suggests to use sendmail but I already have ssmtp installed on my Asus WL-500gP. I have followed the instructions above to send my /tmp/rsync.log file but the email does not come through correctly.

Here is my /tmp/rsync.log file

root@host:~# more /tmp/rsync.log 
Subject: Backup Complete on 04/25/08 7:56 AM
building file list ... done

Number of files: 2461
Number of files transferred: 0
Total file size: 14539518 bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 54985
File list generation time: 0.356 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 55005
Total bytes received: 20

sent 55005 bytes  received 20 bytes  4075.93 bytes/sec
total size is 14539518  speedup is 264.23

Here is the command I'm issuing.

root@host:~# cat /tmp/rsync.log | ssmtp -vvvvv my@emailaddress.com

Here is the email I'm receiving. Note that "building file list ... done" is not in the email I'm receiving, but it is in the log.

Number of files: 2461
Number of files transferred: 0
Total file size: 14539518 bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 54985
File list generation time: 0.356 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 55005
Total bytes received: 20

sent 55005 bytes  received 20 bytes  4075.93 bytes/sec
total size is 14539518  speedup is 264.23

When rsync does find changes to files, it lists them in the /tmp/rsync.log file but they don't get emailed to me similar to the "building file list ... done"

Is there some kind of command that must precede this? can anyone think of why this is happening.

(Last edited by scsikid on 25 Apr 2008, 13:16)

RTFM.

ssmtp expects a mail stream on standard input. The header is separated by an empty line.

Hi, I have installed ssmtp in OpenWrt (r6), but not really send any mail.

This is my configuration of /etc/ssmtp/ssmtp.conf

root=miname@gmail.com
mailhub=smtp.gmail.com:587
rewriteDomain=
hostname=smtp.gmail.com:587
FromLineOverride=YES
UseTLS=YES
UseSTARTTLS=YES
#UseTLSCert=YES
#TLSCert=/etc/ssl/certs/ssmtp.pem
#Debug=YES
AuthUser=miname
AuthPass=12345678


and this configuration of /etc/ssmtp/revaliases

root:miname@gmail.com:smtp.gmail.com:587
mainuser:miname@gmail.com:smtp.gmail.com:587

any suggestions?, thanks.

Juan Carlos

(Last edited by aviador58 on 14 Mar 2012, 02:50)

aviador58 wrote:

Hi, I have installed ssmtp in OpenWrt (r6), but not really send any mail.

This is my configuration of /etc/ssmtp/ssmtp.conf

root=miname@gmail.com
mailhub=smtp.gmail.com:587
rewriteDomain=
hostname=smtp.gmail.com:587
FromLineOverride=YES
UseTLS=YES
UseSTARTTLS=YES
#UseTLSCert=YES
#TLSCert=/etc/ssl/certs/ssmtp.pem
#Debug=YES
AuthUser=miname
AuthPass=12345678


and this configuration of /etc/ssmtp/revaliases

root:miname@gmail.com:smtp.gmail.com:587
mainuser:miname@gmail.com:smtp.gmail.com:587

any suggestions?, thanks.

Juan Carlos

I think hostname= is wrong. hostname is for the hostname of the box you are sending from.


     ssmtp reads configuration data from /etc/ssmtp/ssmtp.conf The file contains keyword-argument pairs, one per line.  Lines starting
     with '#' and empty lines are interpreted as comments.

     The possible keywords and their meanings are as follows (both are case-insensitive):

     Root    The user that gets all mail for userids less than 1000. If blank, address rewriting is disabled.

     Mailhub
             The host to send mail to, in the form host port | IP_addr port [: port].  The default port is 25.

     RewriteDomain
             The domain from which mail seems to come.  for user authentication.

     Hostname
             The full qualified name of the host.  If not specified, the host is queried for its hostname.

     FromLineOverride
             Specifies whether the From header of an email, if any, may override the default domain.  The default is ``no''.

     UseTLS  Specifies whether ssmtp uses TLS to talk to the SMTP server.  The default is ``no''.

     UseSTARTTLS
             Specifies whether ssmtp does a EHLO/STARTTLS before starting SSL negotiation.  See RFC 2487.

     TLSCert
             The file name of an RSA certificate to use for TLS, if required.

     AuthUser
             The user name to use for SMTP AUTH.  The default is blank, in which case SMTP AUTH is not used.  sent without

     AuthPass
             The password to use for SMTP AUTH.

     AuthMethod
             The authorization method to use.  If unset, plain text is used.  May also be set to ``cram-md5''.

Really great, I have used this to send a mail to my friend who are also an active member of this openwrt. I am satisfied with the quality provided by this.. Thanks !

Hi, I changed the "hostname=   ", but still can not send mail, I have checked in envoys and does not appear, I have installed the package "ssmtp_2.64-4_brcm63xx.ipk", will need to install some paque more?.

Use this command line to send mail
ssmtp mi_direccion@gmail.com < mensaje.txt

Also have tried
cat mensaje.txt | ssmtp -v mi_direccion@gmail.com

but any positive effect.

Juan Carlos

(Last edited by aviador58 on 15 Mar 2012, 16:25)

i usually use 'mail' with ssmtp so i wrote this script...

/usr/bin/mail :

#/bin/sh
(
        while [ $# -ne 0 ] ; do
                case "$1" in
                -s)
                        echo "Subject:$2"
                        shift 2
                        ;;
                -c)
                        echo "Cc:$2"
                        shift 2
                        ;;
                -b)
                        echo "Bcc:$2"
                        shift 2
                        ;;
                *)
                        echo $1 >> /tmp/$$.tmp
                        shift
                        ;;
                esac
        done
        cat
) | ssmtp $(cat /tmp/$$.tmp)
rm /tmp/$$.tmp

example:

echo hello | mail -vvv -s test -F yourmama you@gmail.com

(Last edited by luc346 on 4 May 2013, 02:41)

The discussion might have continued from here.