uuencode attaches file at the beginning of the mail body - email-attachments

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

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.

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

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

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.

how to send an email via mailx with enclosed file

I need to sent a file via mailx or mail, but I wat to sent it as attachment not in the body message. Is there any way how to do it ?
Eventually is there any other tool in solaris which can be used for such as procedure ?
Thanks
You can attach files to mailx using -a like so
echo "this is the body of the email" | mailx -s"Subject" -a attachment.jpg Someone#Domain.com
so long as your in the same directory as your attachment that should work fine. If not you can just state the directory like `
samachPicsFolder/samachpic.jpg
If your mailx doesn't support the -a option and you don't have access to mutt, and you don't want to turn to uuencode as a fallback from the 1980s, as a last resort you can piece together a small MIME wrapper yourself.
#!/bin/sh
# ... do some option processing here. The rest of the code
# assumes you have subject in $subject, file to be attached
# in $file, recipients in $recipients
boundary="${RANDOM}_${RANDOM}_${RANDOM}"
(
cat <<____HERE
Subject: $subject
To: $recipients
Mime-Version: 1.0
Content-type: multipart/related; boundary="$boundary"
--$boundary
Content-type: text/plain
Content-transfer-encoding: 7bit
____HERE
# Read message body from stdin
# Maybe apply quoted-printable encoding if you anticipate
# overlong lines and/or 8-bit character codes
# - then you should change the last body part header above to
# Content-Transfer-Encoding: quoted-printable
cat
cat <<____HERE
--$boundary
Content-type: application/octet-stream; name="$file"
Content-disposition: attachment; filename="$file"
Content-transfer-encoding: base64
____HERE
# If you don't have base64 you will have to reimplement that, too /-:
base64 "$file"
cat <<____HERE
--$boundary--
____HERE
) | sendmail -oi -t
The path to sendmail is often system-dependent. Try /usr/sbin/sendmail or /usr/lib/sendmail or ... a myriad other weird places if it's not in your PATH.
This is quick and dirty; for proper MIME compliance, you should do RFC2047 encoding of the subject if necessary, etc, and see also the notes in the comments in the code. But for your average US-centric 7-bit English-language cron job, it will do just fine.
Regarding mailx, you can find some inspiration here
http://www.shelldorado.com/articles/mailattachments.html
I would recommend you to have a look at mutt
http://www.mutt.org/
Try using this command in order to send an attachment using Mailx:
uuencode source_file encoded_filename |mailx -m -s "Subject" something#something.com
I'd recommend using mutt for it, which is light-weight enough to quickly install on any system.