How do you send two body parts as part of the main message?
I am attempting to send two text lines as part of the main (inline) mail message. The result is a main message using the first test message and an attachment for the second. How do I get both lines of text into the main message? I am using the following code fragement.
String d_email = from,
d_password = pword,
//d_host = "smtp.gmail.com",
d_host = host,
//d_port = "465",
d_port = port,
m_to = to,
m_subject = subject,
m_text ="test";
Properties props =new Properties();
props.put("mail.smtp.user", d_email);
props.put("mail.smtp.host", d_host);
props.put("mail.smtp.port", d_port);
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth","true");
//props.put("mail.smtp.debug", "true");
props.put("mail.smtp.socketFactory.port", d_port);
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback","false");
SecurityManager security = System.getSecurityManager();
try
{
Authenticator auth =new SmtpAuthenticator(from, pword);
Session session = Session.getInstance(props, auth);
//session.setDebug(true);
MimeMessage msg =new MimeMessage(session);
msg.setSubject(m_subject);
msg.setFrom(new InternetAddress(d_email));
msg.addRecipient(Message.RecipientType.TO,new InternetAddress(m_to));
MimeMultipart mp =new MimeMultipart("related");
MimeBodyPart mbp1 =new MimeBodyPart();
mbp1.setText(m_text);
mbp1.setDisposition(Part.INLINE);
mp.addBodyPart(mbp1);
MimeBodyPart mbp2 =new MimeBodyPart();
mbp2.setText("test2");
mbp2.setDisposition(Part.INLINE);
mp.addBodyPart(mbp2);
msg.setContent(mp);
Transport.send(msg);
}
catch (Exception mex)
{
mex.printStackTrace();
}

