How to use html tags in a multipart email message. When I use <b>
its not recognized as the bold tag.
views:
256answers:
4You are setting the Content-type mime to text/html on that part of the email message?
Alternatively are you viewing using Outlook - Outlook's viewer uses Word, of all things, to render HTML, instead of using the IE rendering engine like any sensible design would do. This does mean that significant formatting can be lost.
Alternatively, try a different font. A couple of fonts don't define bold variants. This is a long shot though, most font rendering techniques can auto-bold a non-bold font.
which programming language you are using to send email.
In any language a option should be there like "IsBodyHtml". To do the "True" this check. Like code of .NET
System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage(); mm.IsBodyHtml = true;
So the mail will go as html text.
It is a bit difficult to have a definitive answer to this question. There are many reasons why things may not work. These are some things you could check to try to isolate the problem.
Are other html tags recognised? eg. <p>
, <a>
? If so, have you tried using a <strong>
tag instead of <b>
?
Check the message source in the email reader. Maybe the '<' or '>' characters have been escaped as '<' or '>' before it was sent.
Have you tried viewing the email in a different reader, say webmail or desktop based?
Try using CSS to change the font-weight:
.important-text { font-weight: bold; }
<span class=".important-text">Super important text</span>
Ah, you're using Java.
Note that in my opinion, you should always set a plain text alternative in a HTML email.
This code also lets you inline images (referenced from the HTML with <img src="cid:foo">
, but not all email clients support this.
MimeMessage mm = prepareMessage(from, to, subject, cc, bcc);
MimeMultipart mp = new MimeMultipart("alternative");
// Attach Plain Text
MimeBodyPart plain = new MimeBodyPart();
plain.setText(plainText);
mp.addBodyPart(plain);
/*
* Any attached images for the HTML portion of the email need to be encapsulated with
* the HTML portion within a 'related' MimeMultipart. Hence we create one of these and
* set it as a bodypart for the overall message.
*/
MimeMultipart htmlmp = new MimeMultipart("related");
MimeBodyPart htmlbp = new MimeBodyPart();
htmlbp.setContent(htmlmp);
mp.addBodyPart(htmlbp);
// Attach HTML Text
MimeBodyPart html = new MimeBodyPart();
html.setContent(htmlText, "text/html");
htmlmp.addBodyPart(html);
// Attach template images (EmailImage is a simple class that holds image data)
for (EmailImage ei : template.getImages()) {
MimeBodyPart img = new MimeBodyPart();
img.setContentID(ei.getFilename());
img.setFileName(ei.getFilename());
ByteArrayDataSource bads = new ByteArrayDataSource(ei.getImageData(), ei.getMimeType());
img.setDataHandler(new DataHandler(bads));
htmlmp.addBodyPart(img);
}
mm.setContent(mp);