Operating System - HP-UX
1827811 Members
2011 Online
109969 Solutions
New Discussion

HTML + attachment in the same mail

 
Stefan.yu
Occasional Advisor

HTML + attachment in the same mail

Hi all,

I am working on UNIX (Solaris28). I would like to send an email in which the body will be in html format and a file will be attached.
I have tried this but the body comes as html source and not formatted.

cat /tmp/mail.html ; uuencode file.xls file.xls ) | /usr/lib/sendmail -t "myname@mydomain.com"

The mail.html file conatins the following text:
From: myname2@mydomain.com
Content-Type: text/html
Content-Transfer-Encoding: 7bit



Title of page


This is my first homepage. This text is bold




Any help would be greatly appreciated.
Stefan.
13 REPLIES 13
Geoff Wild
Honored Contributor

Re: HTML + attachment in the same mail

Try Steven script in this thread:

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=202647&admit=-682735245+1161612452958+28353475

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Stefan.yu
Occasional Advisor

Re: HTML + attachment in the same mail

Hi Geoff,
I tried the script but always the same results. The attachement is linked well but the body is the html source and not the html formatted like I would like to have it.

Any other suggestions from anyone ?

Thank you in advance.
Dejan.
spex
Honored Contributor

Re: HTML + attachment in the same mail

Hi Stefan,

See Frank's response in this thread:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=202647

He passes MIME headers, including Content-Type, directly to sendmail.

PCS
Steven E. Protter
Exalted Contributor

Re: HTML + attachment in the same mail

Shalom Sefan,

I don't think the attachment can be in the body of the email.

If you use this script for the attachment:

http://www.hpux.ws/mailfile2

I think you can easily adapt it to handle the html requirement.

The script is production. Please change the default email address or someone I used to work with is going to be annoyed.

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
Dave La Mar
Honored Contributor

Re: HTML + attachment in the same mail

Stefan -
Well I have stayed away from this since it has been answered so many times in the past.
Attached you will find many examples of using mailx including the attachment.
in your case the command would look somewhat like this -
uuencode YOUR_FILE "YOUR_FILE.htm" | mailx -s "Some Subject" someone@somewhere.com

Note that the attached is our shop's in house doc and not endorsed outside of our business.

Regards,
-dl
"I'm not dumb. I just have a command of thoroughly useless information."
Stefan.yu
Occasional Advisor

Re: HTML + attachment in the same mail

Hi Steven, Hi Spex

Sorry but noone of the 2 solutions works correctly (or maybe i misundertand you).

Spex, with your solution, I do not see anywhere where to put my html source an to see it formatted in my e-mail. I tried to replace the line echo "DMS file attached" >> $fmesg with my html source but what i see in my email is the source code and not what I want.

Steven,
with your solution I see correctly the html text formatted but the attachment is not attachment but directly in the body of the message.

If you have a complete example please describe me in details what are the steps to do and what i have forgotten

So, maybe I was not clear enough so I try to re-ask my question:
I want to have both an attchment linked to my e-mail and html text (not the source but the formatted text).

In other words, The body of the message have to appear in bold, blue, underlined and an attachment should be linked.
I know that:
1/ cat /tmp/mail.html | /usr/lib/sendmail -t "myname@mydomain.com" gives me the correct html format in the body
2/ uuencode file.xls file.xls | /usr/lib/sendmail -t "myname@mydomain.com"
gives me an attchment in my mail

BUT... i am not able to merge both results (it looks like if there is a attachment the body is always giving me the html source code)

Please help to solve that issue...
spex
Honored Contributor

Re: HTML + attachment in the same mail

Dave,

Your suggestion produces a message with an HTML file attachment. Stefan is looking for inline HTML, which is embedded in the message body. The only way I know of doing is this setting the Content-Type MIME header to text/html.

PCS
Stefan.yu
Occasional Advisor

Re: HTML + attachment in the same mail

Dave,

Your suggestions is sending html in an attachment and it is not what I want.
OK, so with Dave's reply I can see that MY question was not clear :(.
Hope my previous mail is clearer ;)

Stefan
spex
Honored Contributor

Re: HTML + attachment in the same mail

Stefan,

I just tested this with Outlook, and and the HTML is rendered without a problem. Here's a step-by-step:

1) Save the attachment to this posting as domail.sh (courtesy of Frank Slootweg).
2) Transfer domail.sh to your server.
3) # chmod +x domail.sh
4) # echo "Test message" > body.html
5) ./domail.sh "subject_line" your@email.addr < body.html

As I mentioned in my last posting, the answer is in this thread:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=202647

PCS
Stefan.yu
Occasional Advisor

Re: HTML + attachment in the same mail

Hi Spex,

Thank you agin for your reply. I agree that your answer is correctly giving me the correct html in the body of my mail... BUT what about the file attachment I want to link to my e-mail ?
In your steps, I can not see anything refering to an attached file i would like to link ...

Regards.
Stefan
Stefan.yu
Occasional Advisor

Re: HTML + attachment in the same mail

Please help... no suggestions????
OldSchool
Honored Contributor

Re: HTML + attachment in the same mail

from a previous post in this thread:


In other words, The body of the message have to appear in bold, blue, underlined and an attachment should be linked.
I know that:
1/ cat /tmp/mail.html | /usr/lib/sendmail -t "myname@mydomain.com" gives me the correct html format in the body
2/ uuencode file.xls file.xls | /usr/lib/sendmail -t "myname@mydomain.com"
gives me an attchment in my mail


This implies that you can, instead do:

1) uuencode file.xls file.xls > /tmp/attached.file
2) cat /tmp/mail.htlm /tmp/attached.file | /usr/lib/sendmail -t ......

give that a try and see how it goes.....



OldSchool
Honored Contributor

Re: HTML + attachment in the same mail

Okay,

I tested this w/ Lotus Notes, result is the body displays the html doc and it has the xls sheet as an attachment, which is I believe what you want.


echo 'MIME-Version: 1.0' > somefile.out
echo 'Content-Type: multipart/mixed; boundary="abcdefgabcdefg"' >> somefile.out
echo '--abcdefgabcdefg' >> somefile.out
echo 'Content-Type: text/html; charset=us-ascii' >> somefile.out
cat your.html >> somefile.out
echo '--abcdefgabcdefg' >> somefile.out
uuencode some.xls some.xls > somefile.out

cat somefile.out | sendmail -t your.name@yourmail.com