I don't understand the issue at all. If I'm trying from main method while running as java application, then the mail is coming perfectly with proper subject and content formatted. while when I try from localhost , it comes in broken format such as
------=_Part_0_1765202668.1460463643056 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit
My Content
------=_Part_0_1765202668.1460463643056--
I have added all the relevant jars(javax.mail). No matter what the content is, it'll come as such only. It's the same piece of code which works well from main methos but doesn't with local host. any ideas?
some relevant code
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(this.from));
if ((this.replyTo != null) && (!this.replyTo.equals("")))
msg.setReplyTo(InternetAddress.parse(this.replyTo));
msg.setSentDate(new Date());
InternetAddress[] address = InternetAddress.parse(this.to);
msg.setRecipients(Message.RecipientType.TO, address);
if (this.cc != null) {
InternetAddress[] address1 = InternetAddress.parse(this.cc);
msg.setRecipients(Message.RecipientType.CC, address1);
}
if (this.bcc != null) {
InternetAddress[] address2 = InternetAddress.parse(this.bcc);
msg.setRecipients(Message.RecipientType.BCC, address2);
}
msg.setSubject(this.subject);
Multipart mp = new MimeMultipart();
MimeBodyPart mbp = new MimeBodyPart();
mbp.setContent(this.body,"text/html;charset=utf-8");
mp.addBodyPart(mbp);
if (this.attachfiles != null) {
for (Enumeration e = this.attachfiles.keys(); e.hasMoreElements();) {
String filename = (String) e.nextElement();
mbp = new MimeBodyPart();
FileDataSource fds = new FileDataSource(
(String) this.attachfiles.get(filename));
mbp.setDataHandler(new DataHandler(fds));
mbp.setFileName(filename);
mp.addBodyPart(mbp);
}
}
msg.setContent(mp);
msg.setSentDate(new Date());
Transport.send(msg);