LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 04-03-2012, 10:07 AM   #1
vishnu_knl
LQ Newbie
 
Registered: Apr 2012
Posts: 3

Rep: Reputation: Disabled
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

Last edited by vishnu_knl; 04-03-2012 at 05:49 PM. Reason: took out a stupid example
 
Old 04-03-2012, 11:41 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,984
Blog Entries: 54

Rep: Reputation: 2742Reputation: 2742Reputation: 2742Reputation: 2742Reputation: 2742Reputation: 2742Reputation: 2742Reputation: 2742Reputation: 2742Reputation: 2742Reputation: 2742
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:
         ~^~
       //   "\\   /\\
       \\    //  //\\\ -------------------
         @  //  ///=\\SCII Ribbon Campaign
           X   /=---=\\gainst HTML E- Mail
          X   ///     \\
        // \\ ----------------------------
     \ //   \\
     \//     \\
              \\
 
1 members found this post helpful.
Old 04-03-2012, 12:15 PM   #3
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,190

Rep: Reputation: 2468Reputation: 2468Reputation: 2468Reputation: 2468Reputation: 2468Reputation: 2468Reputation: 2468Reputation: 2468Reputation: 2468Reputation: 2468Reputation: 2468
Quote:
Originally Posted by vishnu_knl View Post
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---
BankName=CITIBANK
offername=LOAN
interestrate:15%
--------------------

I want my email to look like as follows:

Dear customer,

CITIBANK brings you an exclusive LOAN offer for an interesting rate of Interest of 15% within the next 48 hours.

Thanks & regards
Citibank

------------------------------------------------------
I want my mail to look exactly like the above in the outlook.
Please advise
Ok...I'll advise you quit asking for help in sending spam emails. Why, exactly, should ANYONE here help you shovel out more crap emails like this? And if you DO work for Citibank, wouldn't they already have a professional staff that does nothing BUT electronic/customer communications??
 
Old 04-03-2012, 05:41 PM   #4
vishnu_knl
LQ Newbie
 
Registered: Apr 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
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.
 
Old 04-03-2012, 06:21 PM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,984
Blog Entries: 54

Rep: Reputation: 2742Reputation: 2742Reputation: 2742Reputation: 2742Reputation: 2742Reputation: 2742Reputation: 2742Reputation: 2742Reputation: 2742Reputation: 2742Reputation: 2742
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.
 
Old 04-04-2012, 09:51 AM   #6
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,190

Rep: Reputation: 2468Reputation: 2468Reputation: 2468Reputation: 2468Reputation: 2468Reputation: 2468Reputation: 2468Reputation: 2468Reputation: 2468Reputation: 2468Reputation: 2468
Quote:
Originally Posted by vishnu_knl View Post
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.
Sorry, but I just don't believe you. Picking Citibank as an 'example' is a bit too much to believe, especially with wording that seems pretty carefully thought out. And modifying your original post won't help...I quoted it in my reply, so others can still see it.

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...
 
Old 04-05-2012, 04:27 AM   #7
vishnu_knl
LQ Newbie
 
Registered: Apr 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
Sorry, but I just don't believe you. Picking Citibank as an 'example' is a bit too much to believe, especially with wording that seems pretty carefully thought out. And modifying your original post won't help...I quoted it in my reply, so others can still see it.

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...
TB0ne,

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.
 
Old 04-05-2012, 09:27 AM   #8
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,190

Rep: Reputation: 2468Reputation: 2468Reputation: 2468Reputation: 2468Reputation: 2468Reputation: 2468Reputation: 2468Reputation: 2468Reputation: 2468Reputation: 2468Reputation: 2468
Quote:
Originally Posted by vishnu_knl View Post
TB0ne,
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.

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.
AGAIN...what you're trying to do is pointless. Even IF You send out a perfect HTML email, that format can be ignored/disallowed in pretty much ANY email client. That is, it may be HTML when it leaves your box, but be stripped down to plain text when the receiver gets it.

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.
 
Old 04-05-2012, 10:00 AM   #9
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to configure sendmail only to send mail to external mail account Nivix Linux - Newbie 2 10-23-2008 12:46 AM
Mail Server Issues; Can't Send E-mail (using sendmail) Vegetarian Smoker Linux - Software 1 06-18-2006 02:16 PM
Import Mail from /var/spool/mail (sendmail) to a MailDir Format in Postfix shawnbishop Linux - Software 0 04-06-2006 10:44 AM
Java Mail fails to send a HTML mail eantoranz Programming 1 11-10-2004 01:47 PM
Composing and sending HTML mail from mailx stv_t Solaris / OpenSolaris 2 03-15-2004 03:23 PM


All times are GMT -5. The time now is 01:16 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration