Multipage Email

How to use html tags in a multiuser email message. When I use <b>, it is not recognized as a bold tag.

+3
source share
4 answers

Oh, you use Java.

Please note that, in my opinion, you should always indicate an alternative to plain text in the HTML letter.

This code also allows you to create inline images (link to HTML using <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);
+10
source

Are you setting the mime of type content to text / html in this part of the email?

Outlook - Outlook Word, , HTML, , IE, . , .

. . , .

+1

.

, "IsBodyHtml". "True" . .NET

System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage();       mm.IsBodyHtml = true;

, html.

+1

. , . , , .

html-? . <p>, <a>? , <strong> <b>?

. , '<' ' > ' '& lt;' '& gt;' .

, , - ?

CSS :

.important-text { font-weight: bold; }

<span class=".important-text">Super important text</span>
+1
source

Source: https://habr.com/ru/post/1722670/


All Articles