Problem in sending mail - java program
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.
Re: Problem in sending mail - java program
Hello
and
encode both the text with the platform default encoding. The only way to have control over the encoding is to replace the call by
Code:
setDataHandler(MyDatasource)
by providing a data source that you have implemented yourself.
Re: Problem in sending mail - java program
Hello
Thank you for your response, tested your solution without success. I tested by changing the header, such
Quote:
mbp1.setText(stringBuffer.function toString() {
[native code]
}());
mbp1.setHeader("Content-Type", "text / html; charset =\"iso-8859-1\"");
mbp1.setHeader("Content-Transfer-Encoding", "8bit");
Here are some of the email received:
Quote:
------=_ Part_0_5763977.12
Content-Type: text / html; charset ="utf-8"
Content-Transfer-Encoding: quoted-printable
<html> <body> <p> Dear, </ p> HELLO WORD </ p> Our Service
Re: Problem in sending mail - java program
Hello
You can try the following part of code, may be, this will help you.
Quote:
DataHandler data = new DataHandler(stringBuffer.function toString() {
[native code]
}(), "text / html; charset = UTF-8");
mbp1.setDataHandler(data);
Re: Problem in sending mail - java program
Hi
Alternatively you can try this code, I have not tried it at my home still you can try and reply with your answer. You must also implement your own data source, she will give the content type, content, etc.
Quote:
mbp.setDataHandler(new DataHandler(mdatas));
//...
Public class mdatas implements DataSource{
Public String getContentType(){.....}
Public InputStream getInputStream() {......}
Public String getName() {.....}
Public OutputStream getOutputStream(){return null;}
}
Hope this will help you.
Re: Problem in sending mail - java program
Hello everyone,
And well after a good time galley, I finally found it. there is a conflict between the jar "geronimo-javamail_1.4_spec-1.3.jar geronimo-andactivation_1.1_spec-1.0.2.jar. And those of "activation.jar"And"javamail.jar". Thank you to participants.