dcsimg
setFrom() and setSubject() won't work (while setText() and setRecipients() do)
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Stefan_Schulte
Posted On:   Monday, October 20, 2008 12:32 PM

Hi, I've got the following problem with the JavaMail API - when trying to set the subject and "From" (and subsequently, replyTo), this is not working. On the other hand, setText() and setRecipients() work absolutely fine. Furthermore, this is only not working on one of my machines, on the other machines it is working absolutely fine, too. Has anybody ever heard of something like this? Here comes my code: private void sendMail(Session session, String subject, String url, String content, String recipi, boolean attachment) throws MessagingException, AddressException { final Properties props = session.getProperties(); SMTPMessage msg = new    More>>

Hi,

I've got the following problem with the JavaMail API - when trying to set the subject and "From" (and subsequently, replyTo), this is not working. On the other hand, setText() and setRecipients() work absolutely fine.

Furthermore, this is only not working on one of my machines, on the other machines it is working absolutely fine, too. Has anybody ever heard of something like this?

Here comes my code:

			
private void sendMail(Session session,
String subject, String url, String content,
String recipi, boolean attachment) throws MessagingException,
AddressException {
final Properties props = session.getProperties();
SMTPMessage msg = new SMTPMessage(session);
Address[] address = new Address[1];
address[0] = new
InternetAddress(props.getProperty("mail.smtp.from"));
msg.addFrom(address);
msg.setRecipients(javax.mail.Message.RecipientType.TO,
recipi);
msg.setSubject(subject);
msg.setReplyTo(msg.getFrom());
inhalt = inhalt+"
"+url;
msg.setText(inhalt, "UTF-8");
msg.setSentDate(new Date());
Transport tr = session.getTransport("smtp");
tr.connect(props.getProperty("mail.smtp.host"),props.getProperty("mail.smtp.user"),
props.getProperty("mail.smtp.password"));
msg.saveChanges();
tr.sendMessage(msg, msg.getAllRecipients());
tr.close();
try {
saveSentMail(msg);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
   <<Less
About | Sitemap | Contact