Sponsored Content
Top Forums Shell Programming and Scripting Need help in sending html mail with attachment Post 302933037 by karthik adiga on Tuesday 27th of January 2015 05:42:56 AM
Old 01-27-2015
Need help in sending html mail with attachment

Hi Everyone,
I am facing problems in sending html mail with attachemnt.
I will able to send mail with attachment (plain text ) using mailx -s and uuencode command and
also html mail without attachment using sendmail option.
However I am not able to send html mail along with attachment.Either one of it is working
(html mail or attachment)
Below are the different ways I have tried. Could you please help me in resolving the same.
1) Failed because of illegal option base64
Code:
#!/usr/bin/ksh
export MAILTO="abc@abc.com"
export SUBJECT="Mail Subject"
export BODY="card_summary_mail.html"
export ATTACH="query5_result.csv"
(
 echo "To: $MAILTO"
 echo "Subject: $SUBJECT"
 echo "MIME-Version: 1.0"
 echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
 echo
 echo '---q1w2e3r4t5'
 echo "Content-Type: text/html"
 echo "Content-Disposition: inline"
 cat $BODY
 echo '---q1w2e3r4t5'
 echo 'Content-Type: application; name="'$(basename $ATTACH)'"'
 echo "Content-Transfer-Encoding: base64"
 echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
 uuencode --base64 $ATTACH $(basename $ATTACH)
 echo '---q1w2e3r4t5--'
) | /usr/lib/sendmail $MAILTO

------------------------------------------------------------
2)
Code:
cib-sokay2{u384283}323:cat test_html2.sh
{
  uuencode query5_result.csv query5_result.csv > attachment.txt
  cat mail.html attachment.txt > attachment2.html
} | /usr/lib/sendmail -t abc@abc.com

-----------------------------------------------
3)
Code:
cib-sokay2{u384283}324:cat test_html3.sh
export MAILTO="abc@abc.com"
export CONTENT="mail.html"
export CONTENT_F="attachment.txt"
export SUBJECT="TEST EMAIL: TESTING HTML"

BOUNDARY='=== This is the boundary between parts of the message. ==='
{
print -  "From: Someone <$MAILFROM>"
print -  "To: Someone <${MAILTO}>"
print -  'Subject:' $SUBJECT
print -  'MIME-Version: 1.0'
print -  'Content-Type: MULTIPART/MIXED; '
print -  '    BOUNDARY='\"$BOUNDARY\"
print -
print -  '        This message is in MIME format.  But if you can see this,'
print -  "        you aren't using a MIME aware mail program.  You shouldn't "
print -  '        have too many problems because this message is entirely in'
print -  '        ASCII and is designed to be somewhat readable with old '
print -  '        mail software.'
print -
print -  "--${BOUNDARY}"
print -  'Content-Type: TEXT/PLAIN; charset=US-ASCII'
print -
cat $CONTENT
print -
print -
print -  "--${BOUNDARY}"
print -  'Content-Type: TEXT/PLAIN; charset=US-ASCII; name='${CONTENT}
print -  'Content-Disposition: attachment;   filename='${CONTENT_F}
print -
cat ${CONTENT}
print -
print -  "--${BOUNDARY}--"
} | /usr/lib/sendmail ${MAILTO}

------------------------------------------------------------

Code:
cib-sokay2{u384283}326:cat test_html4.sh
#!/usr/bin/ksh
export MAILTO="abc@abc.com"
export CONTENT="mail.html"
export SUBJECT="subject of email"
(
echo "Subject: $SUBJECT"
# This appears in the mail body
cat $CONTENT
# The next line creates the attachment with a suitable extension to read
# with Windows notepad
unix2dos "attachment.txt" | uuencode myattach.txt
echo "."
) | /usr/lib/sendmail $MAILTO

-------------------------------------

Last edited by rbatte1; 01-27-2015 at 10:13 AM.. Reason: Added CODE tags and removed (auto?) EMAIL tags
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Error when sending mail attachment

I have been sending an email attachment from my unix box, but keep getting an error? All though the recipient still receives the email and attachment. Will this error cause problems in the future and how to I cure it? $ uuencode PReSvPRINTER.txt file | mailx -s "File" me@world.com uuencode:... (1 Reply)
Discussion started by: dbrundrett
1 Replies

2. UNIX for Dummies Questions & Answers

Sending attachment thru a mail

Is there any way we can send file attachemnts through mails from a unix server. Does the 'mail' command have such an option ?? (1 Reply)
Discussion started by: Rohini Vijay
1 Replies

3. Shell Programming and Scripting

Sending HTML attachment through mail

Hi I am new to unix and scripting.I am trying to send a html file as an attachment. SUBJECT="Type of Exceptions in Application" TO=Sushovan.Samals@gmail.com SPOOLFILE=/data/reg/tlogs/Monitor.html #echo "Send the E-mail message..." uuencode $SPOOLFILE $SPOOLFILE | mailx -s "$SUBJECT" $TO... (2 Replies)
Discussion started by: sushovan
2 Replies

4. UNIX for Dummies Questions & Answers

How to send html file in a mail not as an attachment but it should display in the mail in table for

Hi The below script working when we are sending the html as attachment can u please guide how to send thesmae data in table form direct in the mail and not in mail attachment . cat Employee.sql SET VERIFY OFF SET PAGESIZE 200 SET MARKUP HTML ON SPOOL ON PREFORMAT OFF ENTMAP ON - HEAD... (0 Replies)
Discussion started by: mani_isha
0 Replies

5. Shell Programming and Scripting

Problem in sending inline html with an attachment using sendmail

MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=border --border Content-Type: text/html Content-Disposition: inline <html><body><h2>This text should be displayed with html formatting</h2></body></html> --border Content-Type: text/plain Content-Disposition: attachment This text... (2 Replies)
Discussion started by: thulasidharan2k
2 Replies

6. UNIX for Dummies Questions & Answers

Sending html email with html attachment

Hello, I have a script which is sending an html file as an attachment. #!/usr/bin/ksh export MAILTO="user@company.com" export CONTENT="/usr/tmp/file.html" export SUBJECT="EmailSubject" ( echo "Subject: $SUBJECT" echo "MIME-Version: 1.0" echo "Content-Type: text/html" echo... (0 Replies)
Discussion started by: sreenathkg
0 Replies

7. Shell Programming and Scripting

Sending a csv attachment and html text together.

Hello, I need to send below text (in a file ABC)as html text in mail body and the same as csv attachment 1,2,3 4,5,6 7,8,9 but to send as html text in mailbody we use echo "Subject: Report " | cat - ABC | /usr/lib/sendmail -t a@xyz.com and to send as an attachment in csv format we... (9 Replies)
Discussion started by: skhichi
9 Replies

8. UNIX for Advanced & Expert Users

Sending mail with attachment

Hi, I am using Sun solaris OS unix server I am trying to send mail with an attachment using below script cat test.txt;uuencode test.txt test.txt|mailx -s "$subject" someone@somewhere I m getting mails but with no attachment. Hence i manipulate the script as below and i am... (2 Replies)
Discussion started by: sv0081493
2 Replies

9. Shell Programming and Scripting

HTML mail with Attachment

Hi, I am using the below code: #!/bin/ksh SUBJ="Send mail from Unix with file attachments" TO=sudha.viswanathan@jpmorgan.com CC=sudha.viswanathan@jpmorgan.com ( cat << ! To : ${TO} Subject : ${SUBJ} Cc : ${CC} ! cat << ! MIME-Version: 1.0 Content-Type: text/html `cat... (1 Reply)
Discussion started by: sudvishw
1 Replies

10. How to Post in the The UNIX and Linux Forums

Sending a mail with different attachment in AIX

How to Send a mail with multiple attachment also differenet extension using uuencode in AIX. Can you please help me. Its so urgent. Thanks. Regards, Swapnil ---------- Post updated at 05:37 AM ---------- Previous update was at 05:35 AM ---------- I have below code. But attachment... (1 Reply)
Discussion started by: Swapnil Mawle
1 Replies
All times are GMT -4. The time now is 10:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy