I have a shell script that uses sendmail function to send email the code is as follows
mailalert(){
sendmail -F Sender-Name -it <<END_MESSAGE
To: [email protected]
Subject: Subject
Message
END_MESSAGE
}
It gets executed whenever I call this function. Now I have a text file which I want to send using sendmail as attachment or as message in the email it sends. How can I do that? I have tried alot of tricks but nothing seems to work. Please Help.
Type
uuencode /path/filename.txt | sendmail -s "subject" user@domain
in your terminal to send mail.this is the actual process to send mail with attachment.
add
uuencode /path/filename.txt
before sendmail command in your script. I mean modify it ashope that can help you.
I have created below script to attach a CSV File. The File is getting generated, but its truncating the header row /column name of CSV incorrectly and also there is one more file thats getting attached with the email, namely 'ATT0001.txt' with every email. Anything wrong that you could found out here?
SCRIPT
Rather strange but I used a different approach as while using
uuencode
it started executing but the cursor stuck atbegin 644 /path/to/file
so I used cat to send my file in the message body.The above code worked perfectly but when I saw the message in my web browser it was fine. But when I saw it in Thunderbird it was not shown correctly. It was like kind of encoded.
So, I'm keeping this question open until I dont find the right solution for now.
When sending mail, even from the command line, it is best to use a program which was designed for that purpose, rather than calling
sendmail
directly. A good all-around command-line e-mail client ismutt
; in particular it has a command-line flag to attach files, which avoids the cumbersome use ofuuencode
:As usual, see
man mutt
for usage information.After searching through numerous useless MAN pages and googling I finally came to this solution:
File to be sent:
test.csv
On Ubuntu you will have uuencode (AIX), provided by the package
sharutils
, which you may need to install (the equivalent on Redhat ismutt
).The biggest problem was to combine sendmail and attachment and at the same time setting the subject. Also on AIX I do not have the
-a attachment
option, like the LINUX Man page suggests.You can also use
mailx
instead ofmail
with exactly the same parameters.