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!

Problem with MimeMessage instance -- help please!

843830May 19 2004 — edited May 26 2004
I hope that one of you guys have had this problem and can help
me as I really need to find a solution.

I am using the java.mail and java.mail.internet set of classes to
send numerous emails in a bulk email program. In the main class
the sequence of the operations performed are:

// cast to email text message type
EmailMessage email = (EmailMessage)msg;

// Get system properties
Properties props = System.getProperties();

// Setup mail server
props.put("mail.smtp.host", host);

// Get session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(false);

// Define message
MimeMessage message = new MimeMessage(session);

// sender
message.setFrom(new InternetAddress(email.getFrom()));

// recipient - TO
Iterator i = email.getToList().iterator();
while (i.hasNext())
message.addRecipient(Message.RecipientType.TO,
new InternetAddress((String)i.next()));

// recipient - CC
i = email.getCCList().iterator();
while (i.hasNext())
message.addRecipient(Message.RecipientType.CC,
new InternetAddress((String)i.next()));

// recipient - BCC
i = email.getBCCList().iterator();
while (i.hasNext())
message.addRecipient(Message.RecipientType.BCC,
new InternetAddress((String)i.next()));

// subject
message.setSubject(email.getSubject());

// send date
// msg.setSentDate(new Date());

// message body
message.setText(email.getMessage());

// Send message
Transport.send(message);

The messages are recieved by the correct recipients.

The problem is that when the message/s are received the subject line is always "Subject Line" which
does not appear anywhere in any of the messages or in any of my source! Stepping through the code
shows me that I amd setting the subject correctly at the line "message.setSubject(email.getSubject());"

The second problem is that the from address is always wrong. Again I know that I am setting
it correctly in the MimeMessage message instance.

I've been through the usual debug steps like setting "session.setDebug(true);" and inserting System.out statements
to watch what is actually being set in both the email instance and the MimeMessage message instance.

My company is relying on me to get this bulk email code working, can anyone help please?

Khalid
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 23 2004
Added on May 19 2004
4 comments
369 views