LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-06-2013, 08:13 AM   #1
rukmeister
LQ Newbie
 
Registered: May 2013
Posts: 2

Rep: Reputation: Disabled
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
 
Old 05-06-2013, 09:26 AM   #2
rukmeister
LQ Newbie
 
Registered: May 2013
Posts: 2

Original Poster
Rep: Reputation: Disabled
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mail sends a .dat file instead of text in body j-me Linux - Server 7 03-06-2013 03:17 AM
how ssmtp email client can receive email delivery golden_boy615 Linux - General 0 05-08-2011 01:14 AM
convert email files with attachment to save as attachment file (metamail?) ted_chou12 Linux - Software 2 04-08-2011 08:01 PM
How to configure an email server that sends email to hotmail with Fedora? acarri Linux - Server 5 03-10-2010 02:05 AM


All times are GMT -5. The time now is 02:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration