Re: send mail with embedded html plus .xls attachment (3169 Views)
Reply
Occasional Advisor
Lynne Frazier
Posts: 8
Registered: ‎02-27-2011
Message 1 of 16 (3,171 Views)

send mail with embedded html plus .xls attachment

I'm new to HP-UX and need some assistance in sending an email containing HTML body and a .csv attachment. I've found
numerous posts on the forum that discuss variations of this, however I cannot find a solution for this particular scenario.

My .html file looks something like this:

# cat email.html


Sample HTML file





I'm able to send the html formatted email with no attachments using the following code:

cat email.html \
| /usr/lib/sendmail -t "someone@domain.com"

=====================================
When I update the code to include the attachement as follows, the email is sent with the attachment but the email body is missing:

echo "To: $p_email\nSubject: $month $year Subject\n" > $mailfile
(cat email.html; \
uuencode ${ofile1} ${ofile1} >> $mailfile) \
| /usr/lib/sendmail -t < ${mailfile}

=====================================
Next I tried the following and received the inline html email body but the .csv file was corrupt.

export MAILTO=someone@domain.com
export SUBJECT="Test Waiver Code email"
export BODY=email.html
export ATTACH=wcode_hdr.csv
EMAIL_BOUNDARY_STRING=Z${RANDOM}${RANDOM}${RANDOM}${RANDOM}

(
echo "To: $MAILTO"
echo "Subject: $SUBJECT"
echo "MIME-Version: 1.0"
echo 'Content-Type: multipart/mixed; boundary="${EMAIL_BOUNDARY_STRING}"'
echo '--${EMAIL_BOUNDARY_STRING}'

echo "Content-Type: text/html charset=us-ascii"
echo "Content-Disposition: inline"
cat $BODY
echo '--${EMAIL_BOUNDARY_STRING}'
echo "Content-Transfer-Encoding: base64"
echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
uuencode $ATTACH $(basename $ATTACH)
) | /usr/sbin/sendmail $MAILTO

Any suggestions?

Thanks
Exalted Contributor
Steven E. Protter
Posts: 33,806
Registered: ‎08-15-2002
Message 2 of 16 (3,171 Views)

Re: send mail with embedded html plus .xls attachment

Shalom,

http://hpux.ws/mailfile2

Try that script.

Change the flipping email address though so my mailbox doesn't get filled.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Exalted Contributor
Steven E. Protter
Posts: 33,806
Registered: ‎08-15-2002
Message 3 of 16 (3,171 Views)

Re: send mail with embedded html plus .xls attachment

My bad,

http://hpux.ws/mailfile2

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Honored Contributor
Jose Mosquera
Posts: 1,013
Registered: ‎06-27-2002
Message 4 of 16 (3,171 Views)

Re: send mail with embedded html plus .xls attachment

Hi,

Please take a look to attached file.

Rgds.
Occasional Advisor
Lynne Frazier
Posts: 8
Registered: ‎02-27-2011
Message 5 of 16 (3,171 Views)

Re: send mail with embedded html plus .xls attachment

Steven,

It appears your example only sends an email with a file attached. I need to attach a file as well as include inline html for the message body.

Thanks
Honored Contributor
Jose Mosquera
Posts: 1,013
Registered: ‎06-27-2002
Message 6 of 16 (3,171 Views)

Re: send mail with embedded html plus .xls attachment

Hi Lynne,

Have you reviewed my attachment?

Rgds.
Occasional Advisor
Lynne Frazier
Posts: 8
Registered: ‎02-27-2011
Message 7 of 16 (3,171 Views)

Re: send mail with embedded html plus .xls attachment

Jose,

I tried your example and received the email with the attachement (not corrupted), but the inline html for the message body did not display correctly. It displayed as a single text line of "email.html" instead of the actual verbiage within my file.

I used your code as follows:

MAILTO=someone@domain.com
SUBJECT="Test Waiver Code email"
FROM=host@domain.com
BODY=`cat email.html`
ATTACH=wcode_hdr.csv
#
#And this last one send both of them, inside email body and an attachment:

(echo "Subject:$SUBJECT\nTo: $MAILTO\nImportance:High\n\n$BODY";uuencode $ATTACH $ATTACH)| /usr/sbin/sendmail $MAILTO

Thanks

Occasional Advisor
Lynne Frazier
Posts: 8
Registered: ‎02-27-2011
Message 8 of 16 (3,171 Views)

Re: send mail with embedded html plus .xls attachment

Jose,

Correction, I see a mistake in my code where I didn't cat the email.html file. I fixed that but still the actual html code with tags is displayed in the email body as opposed to the inline formatted html verbiage.

Lynne
Honored Contributor
Jose Mosquera
Posts: 1,013
Registered: ‎06-27-2002
Message 9 of 16 (3,171 Views)

Re: send mail with embedded html plus .xls attachment

Hi,

Try this:

(echo "Subject:$SUBJECT\nTo: $MAILTO\nImportance:High\n\n`cat email.html`";uuencode $ATTACH $ATTACH)|/usr/sbin/sendmail $MAILTO

Rgds.
Occasional Advisor
Lynne Frazier
Posts: 8
Registered: ‎02-27-2011
Message 10 of 16 (3,171 Views)

Re: send mail with embedded html plus .xls attachment

Jose,

I get the same results, the html is not formatted, the email body displays as follows:


Content-Transfer-Encoding: 7bit
Content-Type: text/html charset=us-ascii

Hello all,



Please find the February 2011 waiver codes. These waiver codes are intended for your use only and should not be forwarded to any other recipients. Thank you!






Honored Contributor
Jose Mosquera
Posts: 1,013
Registered: ‎06-27-2002
Message 11 of 16 (3,170 Views)

Re: send mail with embedded html plus .xls attachment

Ok, so try this one syntax:

(echo "Subject:$SUBJECT\nTo: $MAILTO\nImportance:High\nContent-Type: text/html; charset=us-ascii\n\n$BODY";uuencode $ATTACH $ATTACH)|/usr/sbin/sendmail $MAILTO

Rgds.
Occasional Advisor
Lynne Frazier
Posts: 8
Registered: ‎02-27-2011
Message 12 of 16 (3,170 Views)

Re: send mail with embedded html plus .xls attachment

Tried that already, it removes the .csv attachment and the email body appears as follows:

#Content-Type: text/html Content-Transfer-Encoding: 7bit Content-Type: text/html charset=us-ascii
Hello all,


Please find the February 2011 waiver codes. These waiver codes are intended for your use only and should not be forwarded to any other recipients. Thank you!

begin 644 wcode_hdr.csv M4%)!(%=A:79E
Honored Contributor
Jose Mosquera
Posts: 1,013
Registered: ‎06-27-2002
Message 13 of 16 (3,169 Views)

Re: send mail with embedded html plus .xls attachment

Well, I concentrate in the case that send html code as email body...

MAILTO=someone@domain.com
SUBJECT="Test Waiver Code email"
BODY=`email.html`
HTMLFLAG="Content-type: text/html; charset=us-ascii\Content-Transfer-Encoding: 7bit\nMIME-Version: 1.0"

(echo "Subject:$SUBJECT\nTo:$MAILTO\nImportance:High\n$HTMLFLAG\n\n$BODY")|/usr/sbin/sendmail -t

Rgds.
Occasional Advisor
Lynne Frazier
Posts: 8
Registered: ‎02-27-2011
Message 14 of 16 (3,169 Views)

Re: send mail with embedded html plus .xls attachment

Same results...As soon as I code to include any of the following statements to recognize the html & attachment, it screws up the attachment. I've tried different variations of the following:

Content-Disposition: inline
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0
Content-Disposition: attachment; filename="'$(basename wcode_hdr.csv)'"

I've been told it works on AIX using the -m flag with sendmail, but that flag is not available on HP-UX. There must be something comparable.
Occasional Advisor
Lynne Frazier
Posts: 8
Registered: ‎02-27-2011
Message 15 of 16 (3,169 Views)

Re: send mail with embedded html plus .xls attachment

The content statements to recognize the inline html, work just fine without trying to also add a separate attachment.
Honored Contributor
Jose Mosquera
Posts: 1,013
Registered: ‎06-27-2002
Message 16 of 16 (3,169 Views)

Re: send mail with embedded html plus .xls attachment

Yes, this happens because the html header forces attached file to be included as email body. If you copy the block from "begin" to "end" tags, pastes it on plain file and uudecode-it this you have the original attached file.
#man uuencode (is the same to uudecode)

You must select the most convenient way to send it, as part of email body or an attached file. We worked for it!

If you have felt assisted please do not forget assign points!

Best regards

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.