How to send a mail in HTML format using mailx or mail or sendmail commands
Hi,
I am looking for a way to send an email through a shell script. The email content should be displayed in the HTML format (not just HTML code) for example: I am trying to display the contents of a file as follows: ---File contents--- Fruit1=APPLE Fruit2=ORANGE -------------------- I want my email to look like as follows: I like APPLE more than an orange ------------------------------------------------------ I want my mail to look exactly like the above in the outlook. Please advise Thanks & regards vishnu vardhan |
What did you try yourself?
What was the result? And why this clear SPAM example? * BTW here's 7 reasons why HTML e-mail is EVIL if you didn't know. Code:
~^~ |
Quote:
|
This is not a spam
Guys I thing you took it in a wrong way but i am not advertising or spamming here. my intention was to send out a mail for some other issue i had. but it just happened that i choose it as just an example ( i agree i could have made a better example but i was so rushed up that i just got this in my mind and hence i choose that example)
Believe me this is no spam. ok i will make it clear for you guys with another example: lets take fruits this time :) I like Apple instead of an Orange Please help me in sending out an email with such fonts. This may not only be HTML but can be rich text also. Any thing will do Rich Text or HTML And sorry for taking a horrible example earlier. I didn't think people would consider it as spam. |
Does this local example http://www.linuxquestions.org/questi...-mailx-380855/ work for you? Else see external search results [0|1|2|3] and the links therein.
*BTW you didn't respond to the first two questions I asked. If something doesn't work don't reply "doesn't work" but understand and troubleshoot what you're working with first. |
Quote:
Since you picked Citibank as an example "to send out a mail for some other issue i had"...how about telling us WHAT the "other issue" is? And as unSpawn said, you haven't responded to what doesn't work, or posted follow-ups. Restating the original question tells us nothing new. And be aware that ANYTHING you do with email regarding RTF or HTML is fairly pointless...ALL of it can be overridden by most email clients, and most folks also block incoming images too. Unless, of course, you need that formatting to make it LOOK like a corporate email...like a spammer would... |
Quote:
I dont know how i can justify myself for picking citibank as example because i happened to get a loan from Citibank on the same day as i posted this query so in a hurry, it crossed my mind and i just didn't think it would create such an issue. I modified the original post because of your concern of being it a spam. The other issue i meant was the issue being discussed in this thread. i.e. sending a mail with some formatted text. What I tried and does not work: example 1: y.sh: #!/bin/sh echo "From: aaa@xxx.com" > tempfile # multiple To: lines may be sent for multiple addresses echo "To: aaa@xxx.com" >> tempfile echo "Subject: Test html email" >> tempfile echo "Mime-Version: 1.0" >> tempfile # make sure the boundary is the same each time echo "Content-Type: multipart/alternative; boundary=\"FE4B56ACB234342884748397\";" >> tempfile echo "Content-Disposition: inline" >> tempfile echo "--FE4B56ACB234342884748397" >> tempfile # Your HTML part starts here echo "Content-Type: text/html; charset=ISO-8859-1" >> tempfile echo "Content-Transfer-Encoding: 7bit" >> tempfile echo "<HTML\><HEAD>Title here</HEAD><BODY>" >> tempfile echo "<B>Hello world<br></B>This is where you put any html stuff</br> " >> tempfile echo "<BODY></HTML>">> tempfile echo "--FE4B56ACB234342884748397">>tempfile cat tempfile | sendmail -t # ./y.sh # echo $? 0 # The above example returned an exit status of 0 but i never received the mail Example 2: # cat pm.sh echo "To: address@example.com" > report.csv echo "Subject: Subject" >> report.csv echo "MIME-Version: 1.0" >> report.csv echo "Content-Type: text/html; charset=\"us-ascii\"" >> report.csv echo "Content-Disposition: inline" >> report.csv echo "<html>" >> report.csv echo " some text goes here" >> report.csv echo "</html>" >> report.csv mail -s "Built notification" xxx@yyy.com < report.csv # ./pm.sh # echo $? 0 # This sent out a mail but it looked like this in outlook: To: address@example.com Subject: Subject MIME-Version: 1.0 Content-Type: text/html; charset="us-ascii" Content-Disposition: inline <html> some text goes here </html> BUT when i added some body tag to the html code as follows, it did not generate the mail. # cat pm.sh echo "To: address@example.com" > report.csv echo "Subject: Subject" >> report.csv echo "MIME-Version: 1.0" >> report.csv echo "Content-Type: text/html; charset=\"us-ascii\"" >> report.csv echo "Content-Disposition: inline" >> report.csv echo "<html>" >> report.csv echo "<head> some header</head> <body><b> some text goes here</b></body>" >> report.csv echo "</html>" >> report.csv mail -s "Built notification" xxx@yyy.com < report.csv # ./pm.sh # echo $? 0 # Example 3: #!/bin/sh ( echo "From: xx@yy.com " echo "To: aa@bb.com " echo "MIME-Version: 1.0" echo "Content-Type: multipart/alternative; " echo ' boundary="some.unique.value.ABC123/server.xyz.com"' echo "Subject: Test HTML e-mail." echo "" echo "This is a MIME-encapsulated message" echo "" echo "--some.unique.value.ABC123/server.xyz.com" echo "Content-Type: text/html" echo "" echo "<html> <head> <title>HTML E-mail</title> </head> <body> <a href='http://www.google.com'>Click Here</a> </body> </html>" echo "--some.unique.value.ABC123/server.xyz.com" ) | mailx -t # ./dat.sh Ignoring header field "MIME-Version: 1.0" Ignoring header field "Content-Type: multipart/alternative; boundary="some.unique.value.ABC123/server.xyz.com"" # echo $? 0 # This did not work either. the above ignore messages were displayed and No mail sent The actual Purpose of my query: I intend to build and test my code and i have different configurations that can trigger this builds. I need to generate email whenever a build fails of a test fails and I was looking for a much better looking emails with formatted text, that could highlight the configuration and trigger names that caused this failure. Thats the only intent i have and i am not a spammer. |
Quote:
A good way to test this would be to write a simple web-page with whatever message you want, and make it look right in a browser. Once you're happy with it, you can test your email programs and make sure your sending/receiving is working correctly. After you're sure both are working, you can THEN customize the page. Again, keep it simple: take your test page, and simply substitute the sample text in it for the REAL text, and send away. |
well then, I can only say you look for "mime messages" (nevermind it's a Windows example - MIME is standard)
another tool is this SendEmail which does it all. That's probably the most you will get helped on, the problems are best solved if you do it yourself. good luck PS: moderators you can delete this if I break any rules. |
All times are GMT -5. The time now is 12:20 AM. |