Hello everyone,
I have a concern for sending mail. The following code works perfectly in a test class or a hand. I use exactly the same code in my web application, I get much mail, but the content is HTML is misinterpreted. In short I am unable to send mail using this java program. I explored the trails related charset unsuccessfully
Environment:
java 1.5
Tomcat 5.0
Code:
try {
String = smtp_server PARAM_SMTP_SERVER;
String sender_email = PARAM_SENDER_EMAIL;
String mail_user = PARAM_EMAIL_USER;
String mail_pwd = PARAM_EMAIL_PWD;
Properties props = System.getProperties();
props.setProperty("mail.trans.protocol", "smtp");
props.setProperty("mail.host", Smtp_server);
props.setProperty("mail.user", mail_user);
props.setProperty("mail.password", Mail_pwd);
Session session = mailSession.getDefaultInstance(props, null);
Transport trans = mailSession.getTransport("smtp");
trans.connect(smtp_server, mail_user, mail_pwd);
InternetAddress sendineadd = new InternetAddress(sender_email);
MimeMessage message = new MimeMessage(mailSession);
message.setSubject("Mail Subject");
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(stringBuffer.function toString() {
[native code]
}());
mbp1.setContent(stringBuffer.function toString() {
[native code]
}(),"text / html; charset = ISO-8859-1");
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
message.setContent(mp);
InternetAddress iad =new InternetAddress(myEmail);
message.addRecipient(Message.RecipientType.TO, Iadress);
message.setFrom(sendineadd);
trans.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
trans.close();
}catch (Exception e) {
e.printStackTrace();
}
Please verify the following code.
Bookmarks