vnstati generates a png file which can be redirected to stdout, and I'm trying to mail that png image using the command below - but it is attaching 2 duplicate images instead of just 1.
Can anyone tell me why it's 2 pngs instead of just one??
vnstati -d -o - | mail -s "Subject" email#domain.com --content-type=application/octet-stream --encoding=base64 --content-filename=image.png --attach=-
Thanks
So... the duplicate image was only appearing in Apple Mail - Gmail was only displaying one image correctly.
What fixed it was to remove the additional content-type and encoding information and let 'mail' add it automatically. The result is 1 image in Gmail and 1 image in Apple Mail.
vnstati -d -o - | mail -s "Subject" email#domain.com --content-filename=image.png --attach=-
Done. :)
Related
here I'm working on sun Solaris 10, I have tried before to send a normal email with and without attach and its worked fine with me , but now I'm trying to cat-file element and send attach in the same email but it does not work
this is my result.txt file body :
Total Number of Files = 8
Total Number of Fixed Files = 4
Total Number of Notification Files = 4
Total Number of Courrpted Files = 0
Total Execution Time = 3 Seconds.
this is my data.txt file body :
Notification Files :
file number 1
file number 2
unix command :
RECEIPIENTS="mm#gmail.com"
SUBJECT="!! testtt !!"
(cat Results.txt ; uuencode Data.txt Data.txt) | mailx -s "$SUBJECT" -c mm#gmail.com,dd#gmail.com -r zz#gmail.com $RECEIPIENTS
this is what i got after sending the email :
Total Number of Files = 8
Total Number of Fixed Files = 4
Total Number of Notification Files = 4
Total Number of Courrpted Files = 0
Total Execution Time = 3 Seconds.
begin 777 Data
M#0I.;W1I9FEC871I;VX#1FEL97,#.B -"#T*,2U#1$M(34LU2D]21DPP,#0R
M,#T*,BU#1$Q454]-2D]21DPP-S$Q- T*,RU#1$Q454]-2D]21DPP-S$Q-#T* M-"U#1$Q604Q-2D]21DPP-#0U, T*#0I&:7AE9"!&:6QE<R Z( T*#0HQ+4-$ M051'2SE*3U)&3# P,3$T#0HR+4-$051'2SE*3U)&3# P,3$U#0HS+4-$0TA.
C0U5*3U)&3#,Q.3DT#0HT+4-$0TA.0U5*3U)&3#,Q.3DU#0HU
end
note: if I use echo or echo -e or attach the file with uuencode without cat its worked fine, the problem only when I use cat with uuencode
There was a time in the last millennium when uuencode made sense, but you really should be using MIME instead in this day and age.
Here is a simple Python 3 script which combines a message from standard input with an attachment into a valid RFC822 message which you can send with sendmail or similar. It is rather closely based on the Python documentation's examples.
#!/usr/bin/env python3
from email.message import EmailMessage
import sys
msg = EmailMessage()
msg['From'] = sys.argv[1]
msg['To'] = sys.argv[2]
msg['Subject'] = sys.argv[3]
# Don't mess with the preamble, the documentation is wrong to suggest you do
msg.set_content(''.join([line for line in sys.stdin]))
with open(sys.argv[4], 'r') as attachment:
msg.add_attachment(attachment.read(), maintype='text', subtype='plain')
print(msg.as_string())
To use this in your example,
# If `sendmail` is not in your `PATH`, maybe add it.
# For example, if you have it in `/usr/lib/sendmail`
# and `/usr/libĀ“ is not in your `PATH`, you can add it with
#PATH=$PATH:/usr/lib
# Don't use upper case for private variables; check spelling of "recipients"
# To demo an example of sending to multiple addresses, adds a second recipient
recipients="mm#gmail.com,another#example.com"
subject="!! testtt !!"
python3 path/to/script.py "zz#gmail.com" "$recipients" "$subject" Data.txt <Results.txt |
sendmail -oi -t
You can leave out the pipe to sendmail to see what the message looks like. Instead of uuencode smack dab in the message body, it creates a multipart MIME message with two parts, one of which is inline and contains the text from standard input, and another which is properly tagged as an attachment. It's slightly bulky, but I'm including an example here just to show you.
From: zz#gmail.com
To: mm#gmail.com,another#example.com
Subject: !! testtt !!
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="===============2189027902917283968=="
--===============2189027902917283968==
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Total Number of Files = 8
Total Number of Fixed Files = 4
Total Number of Notification Files = 4
Total Number of Courrpted Files = 0
Total Execution Time = 3 Seconds.
--===============2189027902917283968==
Content-Type: text/plain
Content-Transfer-Encoding: base64
MIME-Version: 1.0
Content-Disposition: attachment
Tm90aWZpY2F0aW9uIEZpbGVzIDogCmZpbGUgbnVtYmVyIDEKZmlsZSBudW1iZXIgMgo=
--===============2189027902917283968==--
The attachment is rather needlessly base64-encoded in this particular example; you can tweak the Python code if you absolutely need it to be human-readable (but then neither was the uuencode).
(Also, no idea why the body part has a separate MIME-Version: header -- that seems like a bug.)
Does sendmail command returns any errors if we use wrong email id with correct e-mail id pattern?
If it is not how to identify if e-mail is delievered?
Yes Nitin, unix does give an output if the email remains undelivered. you can check in /var/spool/mail/home_dir
For example
mailx correct_addr#domain.com -s "Success Tested" correct_addr#domain.com < /tmp/dileep/test.txt
correct_addr#server:
you will see the prompt back to you, else look below
mailx correct_addr#domain.com -s "Success Tested" wrong_addr#domain.com < /tmp/dileep/test.txt
You have mail in /var/spool/mail/home_dir
correct_addr#server:
you can go and check the error message, if you would like to check or automate, you can monitor the home_dir for any mail delivery failures and send one email to you will all the details attached to the email and find out the wrong addresses.
NOTE: This works the same way for To and From addresses as well.
I am sending mail in Postfix through a filter, where Altermime applies a signature. I'd like to attach an image to the mail, so i can use html (applied by Altermime) that displays the attached image, eg:
<img src="cid:pic.jpg" />
How can I attach a file to the email when using a bash filter?
I have tried piping it with uuenview at the end of the filter to postfix, but it does nothing:
uuenview /path/to/pic.jpg | $SENDMAIL -i "$#" <in.$$
I'm using the filter method as described in: http://www.postfix.org/FILTER_README.html
OK, I realize it is not as easy as piping uuenview to the mail. Emails are broken up with boundaries.
So instead I will work on getting AddAttachFilter working: http://sourceforge.net/projects/addattachfilter/files/
I have had a little bit success so far this morning with it.
I'm using getmail + maildrop + mutt + msmtp chain with messages stored in Maildir. Very big inbox bothers me, so i wanted to organize mail by date like that:
Maildir
|-2010.11->all messages with "Date: *, * Nov 2010 *"
|-2010.12->same as above...
|-2011.01
`-2011.02
I've googled much and read about mailfilter language, but still it is hard for me to write such filter. Maildrop's mailing list archives has almost nothing on this (as far as i scanned through it). There is some semi-solution on https://unix.stackexchange.com/questions/3092/organize-email-by-date-using-procmail-or-maildrop, but i don't like it, because i want to use "Date:" header and i want to sort by month like "YEAR.MONTH" in digits.
Any help, thoughts, links, materials will be appreciated.
Using mostly man pages, I came up with the following solution for use on Ubuntu 10.04. Create a mailfilter file called, for example, mailfilter-archive with the following content:
DEFAULT="$HOME/mail-archive"
MAILDIR="$DEFAULT"
# Uncomment the following to get logging output
#logfile $HOME/tmp/maildrop-archive.log
# Create maildir folder if it does not exist
`[ -d $DEFAULT ] || maildirmake $DEFAULT`
if (/^date:\s+(.+)$/)
{
datefile=`date -d "$MATCH1" +%Y-%m`
to $DEFAULT/$datefile
}
# In case the message is missing a date header, send it to a default mail file
to $DEFAULT/inbox
This uses the date command, taking the date header content as input (assuming it is in RFC-2822 format) and producing a formatted date to use as the mail file name.
Then execute the following on existing mail files to archive your messages:
cat mail1 mail2 mail3 mail4 | reformail -s maildrop mailfilter-archive
If the mail-archive contents look good, you could remove the mail1, mail2, mail3, mail4, etc. mail files.
as im using different email clients to read/send my mails i want to setup procmail to move my emails to a the folder which is normally done by Thunderbird filter feature.
I know that i can do it by using the following code for procmail in my email users .procmailrc file:
:0:
* ^From:.test#host.name.com
myfolder
But i have a list of about 50 email adresses which i would like to move to that specific "myfolder".
So by using
:0:
* ^From:.first#mail.com
* ^From:.second#mail.com
jimsmail
doesnt help, because procmail interprets them by using the AND operater. So the code above would be true if From is first#... AND second#..., which will never be true.
So how do i use the OR operator.
Actually i have a simple text file where all email adresses are.
Would be cool to have a feature where procmail ready in that file and checks if From matches with at least one of the lines in the file, the moves email to "myfolder".
Something like
:0:
* ^From:file(email.txt)
myfolder
Does anybode if this or something similar is possible.
I dont want to add these 3 lines 50 times in my procmailrc file.
Procmail uses regexps, so you can separate addresses with the | character.
:0:
* ^From:.((first|second|third)#mail.com|(fourth|fifth)#othermail.com)
myfolder
would work. Could get a little messy with fifty all on one line, mind...
I found the solution.
With this solution im able to use a simple email text file holding all email addresses in each in one line.
The code in my .procmailrc is as follows:
EMAILFILE=/path/to/my/emailfile
FROM=`formail -xFrom: | sed -e 's/ *(.*)//; s/>.*//; s/.*[:<] *//'`
:0
* ? fgrep -qxis $FROM $EMAILFILE
myfolder