Posted By:
sailaja_N
Posted On:
Wednesday, September 23, 2009 03:29 AM
Hi, I am new to java Mail, can any one help me. I am using the below code, public void postMail(MailData mailData) { boolean debug = false; try { Properties props = new Properties(); props.put("mail.smtp.host", rb.getString("mail.smtp.host")); props.put("mail.smtp.auth", rb.getString("mail.smtp.auth")); props.put("mail.debug", rb.getString("mail.debug")); props.put("mail.smtp.user", rb.getString("mail.smtp.user")); props.put("mail.smtp.password", rb.getString("mail.smtp.pass
More>>
Hi,
I am new to java Mail, can any one help me.
I am using the below code,
public void postMail(MailData mailData) {
boolean debug = false;
try {
Properties props = new Properties();
props.put("mail.smtp.host", rb.getString("mail.smtp.host"));
props.put("mail.smtp.auth", rb.getString("mail.smtp.auth"));
props.put("mail.debug", rb.getString("mail.debug"));
props.put("mail.smtp.user", rb.getString("mail.smtp.user"));
props.put("mail.smtp.password",
rb.getString("mail.smtp.password"));
props.put("mail.smtp.port", rb.getString("mail.smtp.port"));
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getDefaultInstance(props, auth);
session.setDebug(debug);
Message msg = new MimeMessage(session);
InternetAddress addressFrom = new InternetAddress(mailData.getFrom());
msg.setFrom(addressFrom);
InternetAddress[] sendTo = new InternetAddress[mailData.getToList().size()];
for (int i = 0; i
< mailData.getToList().size(); i++) {
sendTo[i] = new InternetAddress((String)
mailData.getToList().get(i));
}
msg.setRecipients(Message.RecipientType.TO, sendTo);
if (mailData.getCcList() != null && mailData.getCcList().size() != 0) {
InternetAddress[] ccTo = new InternetAddress[mailData.getCcList().size()];
for (int i = 0; i
< mailData.getCcList().size(); i++) {
ccTo[i] = new InternetAddress(mailData.getCcList().get(i));
}
msg.setRecipients(Message.RecipientType.CC, ccTo);
}
msg.addHeader("MyHeaderName", "myHeaderValue");
msg.setSubject(mailData.getSubject());
msg.setContent(mailData.getText(), "text/html");
Transport.send(msg);
} catch (Exception e) {
e.printStackTrace();
}
}
Using this method in my web application if i sent a mail, its sending mail, but subject is not setting,
but the same code if i use as stand alone application the subject is setting
I am not able to find the problem, please help me, i am using Spring web flow for my web application
Thanks and Regards
Sailaja N
<<Less