How to send a PDF attachment via MAILX?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to send a PDF attachment via MAILX?
# 1  
Old 05-02-2018
How to send a PDF attachment via MAILX?


We are using HPUX and have a script to send PDF attachment via MAILX
Basically the script does the following:

echo > $HOME/MY_mail_file
uuencode o40881754.pdf o40881754.pdf  >> MY_mail_file
cat MY_mail_file | mailx -m -s "Sending PDF attachment"  <email address>

This script works fine when sensing the attachment to MS Outlook or Gmail,
but it does not work when using Yahoo mail, we see the PDF attachment but when we try to retrieve it, it fails indicating an invalid format. It appears that Yahoo mail does not know how to decode the attachment done via uuencode.
I've been reading different notes regarding this issue, one suggestion was to use "mutt" but unfortunate it does not seem available for HPUX.
I've also tried MIME/base64 code that I found on different forums but it did not work either.
Has anyone been able to send PDF attachment to Yahoo mail via a Unix command line (ex: Mailx, Sendmail etc..) ?
If so how was this achieved ?
Thanks in advance

Last edited by Corona688; 05-02-2018 at 04:44 PM..
# 2  
Old 05-02-2018
# 3  
Old 05-02-2018
More and more mail clients are abandoning uuencode these days.

Try the uuencode -m option if you have it.
# 4  
Old 05-07-2018
Thanks for the info
We were able to get it to work with a similar piece of code using MIME base64 and sendmail.
But we need to know when an email failed because of an invalid address and was not able to figure it out using sendmail. I also tried "-N failure" but still could not get it to work.
When using "mailx -r" we get an email notification when it failed, but the attachment is not sent properly. When we use "sendmail" the attachment works fine but we don't know if the email failed or not.
We also tried "mpack" which worked great with the attachments but were not able to get a notification on a failure for an invalid address.

Any suggestions ?
# 5  
Old 05-07-2018
What is the exact sendmail command?
Are you using the -f -r or -R options?
# 6  
Old 05-08-2018
This is the code .. As mentioned we can send attachments to gmail, yahoo etc ..
But we would need to know if the email failed because of an invalid address
I tried to convert the code to use mailx but the attachments comes in as text inside the email instead of an attachment.

Any help is appreciated


export MAILTO="<email address>"
export SUBJECT="Test mail PDF"
export ATTACH="1.pdf"
echo "Date: $(date)"
echo "To: $MAILTO"
echo "Subject: $SUBJECT"
echo "MIME-Version: 1.0"
echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
echo '---q1w2e3r4t5'
echo 'Content-Type: text/plain'
echo 'Content-Disposition: inline'
echo "This is a  message for PDF attachment test"
echo '---q1w2e3r4t5'
echo 'Content-Type: application/pdf; name="'$(basename $ATTACH)'"'
echo "Content-Transfer-Encoding: base64"
echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
uuencode -m $ATTACH $(basename $ATTACH)
echo '---q1w2e3r4t5--'
) | /usr/sbin/sendmail $MAILTO

Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 05-08-2018 at 12:41 PM.. Reason: Added CODE tags.
# 7  
Old 05-08-2018
try adding:
echo "From: $FROM"

after the To: line.
change the last line to:
)| /usr/sbin/sendmail -f $FROM $MAILTO

Does uuencode produce the same output as b64encod ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Unable to send attachment using mailx command

I am unable to send email with attachment using the mailx command. Without the attachment, the email goes through file. This is the command I use. Works : $ echo "Test" | mailx -s "Test" Fails : $echo "Test" | mailx -a all-dss-accounts.txt -s "Test"... (3 Replies)
Discussion started by: nkarthik_mnnit
3 Replies

2. Shell Programming and Scripting

Mailx command to send attachment file

Hi, I need to send a attachment which has space in the file name as: "ABC Data Extract.txt" which is present in the location /home/projects/txt i am using /home/projects/scripts mailx -s "Sub" email_id "/home/projects/txt/ABC Data Extract.txt" but i am not getting the attachment. (7 Replies)
Discussion started by: ATWC
7 Replies

3. Shell Programming and Scripting

How to send email HTML + PDF attachment?

I am attempting to write a script where I can pass in parameters ( to , from, the location of a pdf attachment ) and send an email that has HTML for the body content and a PDF as an attachment. I have failed to achieve this with sendmail and mutt. I recently found this. If there are any... (2 Replies)
Discussion started by: jvsrvcs
2 Replies

4. Shell Programming and Scripting

send attachment and body in one mail using mailx

Hi, Our requirement is to send an attachment and content in a single mail. I am using the below command to send attachement. --------------------- (uuencode $exp_file $exp_file) |mailx -s "$email_subject" $EmailRecipients -------------------- I m not able to send any message in the... (4 Replies)
Discussion started by: ashwin3086
4 Replies

5. Shell Programming and Scripting

Mailx: How to send a attachment using mailx command

Hi All, Can anyone please provide the command for sending an mail with attachment using mailx command. Thanks in Advance :) Regards, Siram. (3 Replies)
Discussion started by: Sriram.Vedula53
3 Replies

6. UNIX for Advanced & Expert Users

how to send file as attachment using mail or mailx

I have a need to send a file from the unix command line to be sent as an attachment. Is this possible? That is when I open my outlook email I need to file to appear as an attachment. Also, is there a way to use the mail binary (not mailx) to modify the "reply address". mailx -r works but I need... (1 Reply)
Discussion started by: kieranfoley
1 Replies

7. AIX

Send email from unix (AIX) with PDF attachment

I am using the following command to send PDF attachment with a mail. uuencode <attachment.pdf> <attachment.pdf>|mailx -s <subject> <mail_id> < <Message_file.txt> This one send the message with attachment. I would like send PDF attachment with the mail Can any one help with this issue ? ... (0 Replies)
Discussion started by: sunjup
0 Replies

8. Shell Programming and Scripting

UNABLE to send 5MB attachment using mailx

hi, i've created a script that sends out an email using the mailx and uuencode command. the script is ok, but when a 5MB attachment is sent, there are time that the intended recepients does not receive any email. i tested it and the issue is intermitent. please help on how to troubleshoot. i... (3 Replies)
Discussion started by: tads98
3 Replies

9. Shell Programming and Scripting

HELP!!! how to send PDF file as an attachment using mailx

Hi, iam using the following command: uuencode file1.pdf file1.pdf|mailx - s "waz up?" Iam recieving an encoding error when i try to open the attachment. Pls help..very urgent!!! (1 Reply)
Discussion started by: Brat
1 Replies

10. UNIX for Dummies Questions & Answers

Send a *.pdf file as a attachment

Hi there, i am very new in the unix sector. (i work on HP UX, an Sun Solaris) i can write some simple scripts,..... but now i will wirte a script with "mail". i would like to send a pdf file to a mail recipient. But if i try it with "mail -s "email@adress" < "filename(with path)" it... (3 Replies)
Discussion started by: scotty
3 Replies
Login or Register to Ask a Question

Featured Tech Videos