Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SMTP: Header lines in message body ?

843830Oct 29 2001 — edited Dec 9 2003
Hi
Seems I'm not the first to ask this question, but I didn't really find the answer to it, so I'll post it again myself..

When sending a mail using JavaMail SMTP I got some of the header lines in the message body.
How can this be avoided, or: what am I doing wrong ?

Any help would be highly appreciated
Chris
Code:
===============

private void sendNews(String subject, String summary, String text) {

Properties props = System.getProperties();

String smtphost = Config.get("smtpHost");
if(smtphost != null) {
props.put("mail.smtp.host", smtphost);
}
else {
cat.warn("No smtp host specified - no message will be sent!");
}

// Get a Session object
Session session = Session.getDefaultInstance(props, null);

// construct the message
MimeMessage msg = new MimeMessage(session);

try {
msg.setFrom(ownAddress);
Address[] addresses = new Address[1];
String tmp = Config.get("newsmailDestination");
if(tmp != null) {
cat.info("Sending news to " + tmp + "...");
msg.setRecipients(SMTPMessage.RecipientType.TO, InternetAddress.parse(tmp, false));
}
else {
cat.warn("No recipient address for news specified");
}

msg.setHeader("MIME-Version", "1.0");
msg.setHeader("Content-Type", "text/plain");
msg.setHeader("Content-Transfer-Encoding", "7bit");
msg.setHeader("X-Mailer", "MyMailServer");
msg.setSentDate(new Date());
msg.setSubject(subject);

String msgcontent = summary + "\n\n" + text;
msg.setText(msgcontent, "us-ascii");

msg.saveChanges();

Transport.send(msg);

cat.info("... done");

}
catch(MessagingException mse) {
cat.warn("Sending message failed: " + mse);
}
}


Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 6 2004
Added on Oct 29 2001
2 comments
181 views