Multipart (HTML) email

S

Slattery_T

I'm trying to figure out how to send a multipart email, one text part
and equivalent HTML part. I suppose it should be
multipart/alternative. This is what I've done:

Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(returnAddress, returnName));
msg.setRecipient(Message.RecipientType.TO,
newInternetAddress(rb.getTo()));

Multipart mp = new MimeMultipart("alternative");

// First part: plain text
MimeBodyPart mbp = new MimeBodyPart();
/* stripTags remove HTML tags from my text */
mbp.setText(stripTags(msgBody), "UTF-8", "plain");
mp.addBodyPart(mbp);

MimeBodyPart mbhtml = new MimeBodyPart();
mbhtml.setText(msgBody, "UTF8", "html");
mp.addBodyPart(mbhtml);
msg.setContent(mp);

Transport.send(msg);

And I get IO Exception, no content. I see a method in the javadoc for
MimeBodyPart: setText(text, charset, subtype), all three arguments
Strings. But the compiler says there is no such method.

So how the heck do I put content into this message?
 
A

Arne Vajhøj

I'm trying to figure out how to send a multipart email, one text part
and equivalent HTML part. I suppose it should be
multipart/alternative. This is what I've done:

Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(returnAddress, returnName));
msg.setRecipient(Message.RecipientType.TO,
newInternetAddress(rb.getTo()));

Multipart mp = new MimeMultipart("alternative");

// First part: plain text
MimeBodyPart mbp = new MimeBodyPart();
/* stripTags remove HTML tags from my text */
mbp.setText(stripTags(msgBody), "UTF-8", "plain");
mp.addBodyPart(mbp);

MimeBodyPart mbhtml = new MimeBodyPart();
mbhtml.setText(msgBody, "UTF8", "html");
mp.addBodyPart(mbhtml);
msg.setContent(mp);

Transport.send(msg);

And I get IO Exception, no content. I see a method in the javadoc for
MimeBodyPart: setText(text, charset, subtype), all three arguments
Strings. But the compiler says there is no such method.

So how the heck do I put content into this message?

You got two answers to the question when you posted it
yesterday.

Arne
 
T

Tim Slattery

You got two answers to the question when you posted it
yesterday.

!! My newsreader doesn't show either one. Anyway, I got it working.
setContent works with a String holding the content and a second string
giving type/subtype.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,836
Messages
2,569,748
Members
45,545
Latest member
rapter____0

Latest Threads

Top