Using mailx command for sending mail with attachment and messagebody in UNIX - email

i have been trying to send an email from my script which is generating an excel and then zipping it. i want to send this zipped file as an attachment along with a message body, but no success.
i have been using the below code:
1) uuencode inputFileName OutputFileName | mailx -s "Report" abc#gmail.com -- -f abc#gmail.com
this commandline is successfully sending my attachment
2) uuencode inputFileName OutputFileName | mailx -s "Report" abc#gmail.com -- -f abc#gmail.com < MessageBody.txt
with this commandline, i am trying to send the same attachment with mail body fetched from external file MessageBody.txt, but it is then sending the mail only with mail body, and NO attachment.

You are giving two different sources for stdin. At the beginning of the line you are taking stdin from stdout of uuencode but at the end of the line you are taking stdin from the file MessageBody.txt.
Instead you could try the following:
uuencode inputFileName OutputFileName | cat - MessageBody.txt | mailx -s "Report" abc#gmail.com -- -f abc#gmail.com
regards Henrik

Related

Problems with using uuencode on RHEL to send mail attachment

I have a unique situation where I'm going from an AIX platform to RHEL for a vendor supported application. Within the application, I can send a command (limited to the amount of characters I can send) that will email me results of a print job.
To do this in AIX, I'm passing the following command:
uuencode temp.txt | mail -s "test" email#address.com
This sends standard output to the email as an attachment named temp.txt. Temp.txt doesn't exist on the AIX server.
I have downloaded the rpm for uuencode for Linux, but it doesn't work in the same fashion. It sends an email with what looks like garbage (could be missing MIME header).
I'm looking for a similar command. To simulate outside of the application, I use the following in AIX:
echo "testing mail" | uuencode temp.txt | mail -s "test" email#address.com
I know mailx -a <filename> would work if I had a filename, unfortunately I'm working with standard output vs a file.
Any help will be appreciated.

uuencode attaches file at the beginning of the mail body

I am using below code in AIX and the problem is it attaches the file at the very beginning of the mail, I want to attach the file after the mail body.
(uuencode <filepath> <filename-in-mail>;cat <body-of-the-mail-file>) | mailx -s "Subject" -r <sender-address> <multiple-receiver-addresses>
Any thoughts?, On AIX only uuencode is working, base64 or any other command doesn't work.
I tried a lame change in the code uuencode cat <body-of-the-mail-file>;<filepath> <filename-in-mail> but it gave error

How to add X-header to unix mailx or add attachment to usr/sbin/sendmail

I am attempting to add the x-header X-APP-VOLT: Yes to the header of my email with a .tar attachment. I only have access to usr/sbin/sendmail and mailx. I do not have root access so I can't download other versions of mailx or mutt.
I can add the x-header to usr/sbin/sendmail using the below code, but I can't figure out how to add the .tar attachment.
/usr/sbin/sendmail -i -- toemail << END
To: toemail
Subject: Test
X-APP-VOLT: Yes
Hope this works! END
I can attach a .tar file to mailx using the the below code, but I can't figure out how to add a x-header. My mailx also does not have the -a option.
cat file | uuencode filename | mailx -s "Test" toemail
Thank you
One way is to construct your input in a temporary file:
cat > tmpfile$$ << END
To: toemail
Subject: Test
X-APP-VOLT: Yes
Hope this works!
END
uuencode filename < file >> tmpfile$$
/usr/sbin/sendmail -i -- toemail < tmpfile$$
Also, I usually use sendmail's -t flag in this case, rather than repeating the recipient:
/usr/sbin/sendmail -i -t < tmpfile$$
If you don't want to use a temporary file, if you want to use a pure pipeline, you can use ( ) to create a subshell to do the construction:
(
echo "To: toemail"
echo "Subject: Test"
echo "X-APP-VOLT: Yes"
echo
echo "Hope this works!"
echo
uuencode filename < file
) | /usr/sbin/sendmail -i -t
(Of course, these days most recipients will probably find it easier to deal with MIME attachments rather than uuencode. It's pretty straightforward to create MIME attachments with a shell script, also.)

Mailx with uuencode not sending multiple attachments with a proper email body on Suse Linux

This particular piece of code below worked correctly on AIX
( echo "mailbody";
uuencode a.txt 'arenamed.txt';
uuencode ab.txt 'abrenamed.txt';
uuencode abc.txt 'abcrenamed.txt';
uuencode abcd.txt 'abcdrenamed.txt'; ) | mailx -s "$subject" $emailaddress;
But on Linux, any occurrence of uuencode is printing begin 644 blocks in the body of the email viewed on Outlook 2010.
begin 644 abc.txt
5:F%H<V1L:G-A"F%S9&MJ87-J9#L*
`
end
I have tried, using different variations of ( echo $body ; uuencode filename filenamechanged ) with echo first, uuencode later and vice versa but it doesn't help.
I would have used "mail -a" but I want to rename files which are emailed, so, was looking at uuencode.
Any suggestions other than using sendmail/mutt here?
This is what worked
(echo "Subject: $Mail_Subject";
echo "To:$Mail_List";
echo $Mail_Body;
uuencode $LOG_DIR/FileName1 'AttachmentDisplayName1';
uuencode $LOG_DIR/FileName2 'AttachmentDisplayName2') | sendmail -t $Mail_List
Hope this helps anyone who is looking for this kind of issue.

Sending email with CC BCC and sender's address in unix mailx

I want to send email from HP unix using mailx command.
I have to include cc and bcc in my email and have to use the specific email address as the sender.
But -r (which is to define the sender's email address) will disalbe ~ commands so if i have to define the sender's email address, i cannot use ~c and ~b commands for cc and bcc.
Is there any work around???? cos these are the requirements from the user.
Thanks.
Just re-order the arguments to mailx command. That would give the desired result
$ echo "something" | mailx -s "subject" -b bcc_user#some.com -c cc_user#some.com -r sender#some.com recipient#example.com
In my case I have to keep multiple id's in cc which has been done by giving the email-id's comma separated one by one as below:
$ echo -e "Hi Team, \n \n Action Needed \n \n Regards, \n XYZ team"| mailx -s "subject" -b bcc_user1#some.com,bcc_user2#some.com -c cc_user1#some.com,cc_user2#some.com -r sender#some.com receiver#xyz.com
Also made use of the echo command to pass multiple lines to mailx utility. Thought it will be helpful.