LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   ssmtp sends as email attachment instead of body text (https://www.linuxquestions.org/questions/linux-newbie-8/ssmtp-sends-as-email-attachment-instead-of-body-text-4175460888/)

rukmeister 05-06-2013 08:13 AM

ssmtp sends as email attachment instead of body text
 
Hello,

I would really appreciate any help with this as I'm thoroughly stuck.

I've set up rkhunter to run as a cron job and then email any warnings etc using ssmtp via gmail with this script:

Code:

#!/bin/sh
(
/usr/local/bin/rkhunter --versioncheck
/usr/local/bin/rkhunter --update
/usr/local/bin/rkhunter --cronjob --report-warnings-only
) | /bin/mail -v -s 'rkhunter daily run' myemail@gmail.com

It all works ok, except that it sends the output as an attachment rather in the body.

It happens whether it is run via cron or within a normal shell.

I found a similar problem relating to encoding and tried piping it like this
Code:

[rkhunter outpu] | iconv -c -t UTF-8 | /bin/mail -v -s 'rkhunter daily run' myemail@gmail.com
but that didn't fix it either

/etc/environment has locale set to en_US

I tried setting locale within the scrip like this :
Code:

LOC="en_US"
export LC_ALL=$LOC

This sends text as the body in an email like you would expect:

Code:

echo 'some text' | /bin/mail -v -s 'UTF Test' myemail@gmail.com
and displays :
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

while the output from rkhunter shows this when sent:
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64

rukmeister 05-06-2013 09:26 AM

Ok, a little unstuck now. Putting this up if it helps anyone else. I'm not sure if this is the right way to solve this but it works for now.

Changing the script to this works now
Code:

# send rkhunter output to a file
rkhunter --cronjob --report-warnings-only > /var/log/rkhuntercron.log

# Overwrite old sendthis.txt with file containing TO/FROM/SUBJECT info contained in mailtome.txt that ssmtp expects
cat /etc/cron.daily/mailtome.txt > /etc/cron.daily/sendthis.txt

# Append rkhunter output to sendthis.txt
cat /var/log/rkhuntercron.log >> /etc/cron.daily/sendthis.txt

# Send it with ssmtp
/usr/sbin/ssmtp myemail@gmail.com < /etc/cron.daily/sendthis.txt

In this case mailtome.txt should look like this :
Code:

To: myemail@gmail.com
From: root@myhost
Subject: rkhunter daily cron

However the following still sends it as an attachment! Arrggh! Why?

Code:

cat /var/log/rkhuntercron.log | mail -v -s 'rkhunter mail test' myemail@gmail.com
OUTPUT:
Code:

[<-] 220 mx.google.com ESMTP xxxxxxxxxxxxx.xx - gsmtp
[->] EHLO xxxxxxx.host@gmail.com
[<-] 250 ENHANCEDSTATUSCODES
[->] STARTTLS
[<-] 220 2.0.0 Ready to start TLS
[->] EHLO xxxxxxx.host@gmail.com
[<-] 250 ENHANCEDSTATUSCODES
[->] AUTH LOGIN
[<-] 334 xxxxxxxxxxx
[->] xxxxxxxxxxxxxxxx
[<-] 334 xxxxxxxxxxx
[<-] 235 2.7.0 Accepted
[->] MAIL FROM:<xxxxxxxxx.host@gmail.com>
[<-] 250 2.1.0 OK xxxxxxxxxx.xxx - gsmtp
[->] RCPT TO:<myemail@gmail.com>
[<-] 250 2.1.5 OK xxxxxxxxxxxxx.xx - gsmtp
[->] DATA
[<-] 354  Go ahead xxxxxxxxxx.xx - gsmtp
[->] Received: by xxxxxxxxx.host@gmail.com (sSMTP sendmail emulation); Mon,  6 May 2013 17:54:33 +0400
[->] From: "root" <xxxxxxxxxx.host@gmail.com>
[->] Date: Mon, 06 May 2013 17:54:33 +0400
[->] To: myemail@gmail.com
[->] Subject: rkhunter mail test
[->] User-Agent: Heirloom mailx 12.4 7/29/08
[->] MIME-Version: 1.0
[->] Content-Type: application/octet-stream
[->] Content-Transfer-Encoding: base64



All times are GMT -5. The time now is 08:06 PM.