jrod
asked on
JavaMail - Need help creating multipart message/email!
I am trying to set a mime message with html and text as a multipart "alternative" message and add an attachment. I have the html stored in a string and the text stored in a string. I do not yet have the attachment, but I am assuming that I would just read this into a string also?!? Here is my code so far. I can send email with text or html, but not with both. What am I missing and where would I place the attachment? What import statements do I need to have (show current imports)?
import javax.swing.JOptionPane;
import java.util.*;
import javax.mail.*;
import javax.mail.event.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.io.*;
...
MimeBodyPart textpart=new MimeBodyPart();
textpart.setText(text);
textpart.addHeaderLine("Co ntent-Type : text/plain; charset=\"iso-8859-1\"");
textpart.addHeaderLine("Co ntent-Tran sfer-Encod ing: quoted-printable");
MimeBodyPart htmlpart=new MimeBodyPart();
htmlpart.setText(html,"tex t/html");
htmlpart.addHeaderLine("Co ntent-Type : text/html; charset=\"iso-8859-1\"");
htmlpart.addHeaderLine("Co ntent-Tran sfer-Encod ing: quoted-printable");
Multipart mp=new MimeMultipart("related");
Multipart mp2=new MimeMultipart("alternative ");
mp2.addBodyPart(textpart);
mp2.addBodyPart(htmlpart);
MimeBodyPart bp=new MimeBodyPart();
bp.setContent(mp);
mp.addBodyPart(bp);
message.setContent(mp);
...
import javax.swing.JOptionPane;
import java.util.*;
import javax.mail.*;
import javax.mail.event.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.io.*;
...
MimeBodyPart textpart=new MimeBodyPart();
textpart.setText(text);
textpart.addHeaderLine("Co
textpart.addHeaderLine("Co
MimeBodyPart htmlpart=new MimeBodyPart();
htmlpart.setText(html,"tex
htmlpart.addHeaderLine("Co
htmlpart.addHeaderLine("Co
Multipart mp=new MimeMultipart("related");
Multipart mp2=new MimeMultipart("alternative
mp2.addBodyPart(textpart);
mp2.addBodyPart(htmlpart);
MimeBodyPart bp=new MimeBodyPart();
bp.setContent(mp);
mp.addBodyPart(bp);
message.setContent(mp);
...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Finalized as proposed
modulo
Community Support Moderator
Experts Exchange
modulo
Community Support Moderator
Experts Exchange
I will leave a recommendation in the Cleanup topic area that this question is:
Answered by: Venci75
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Venci75
EE Cleanup Volunteer