JavaMail sending email with no body content

  • Thread starter Steve D. Perkins
  • Start date
S

Steve D. Perkins

Hey everybody -

I'm wondering if anyone's ever seen this issue before. I'm sending
plain SMTP emails in a JSP (on WebSphere 4) using JavaMail 1.3.2, and the
messages are being received with no body.

Below is the basic gist of the block of code sending the emails. I
know some things may look funny (specifying the SMTP server address in
Transport.connect() rather than in the Properties object passed to the
Session constructor, etc)... but I had some weird issues getting the app
to resolve to the right mailserver box, and this is the version of code
we came up with that actually results in emails being sent:


Session mailSession =
Session.getDefaultInstance(new Properties();, null);

MimeMessage mimeMessage = new MimeMessage(mailSession);
mimeMessage.setFrom(new InternetAddress("(e-mail address removed)"));
InternetAddress[] address =
InternetAddress.parse("(e-mail address removed)", false);
mimeMessage.setRecipients(Message.RecipientType.TO, address);
mimeMessage.setSubject("Test @ " + new Date().getTime());

MimeBodyPart mimeBodyPart = new MimeBodyPart();
mimeBodyPart.setText("This is a\ntest\n");

Multipart multiPart = new MimeMultipart();
multiPart.addBodyPart(mimeBodyPart);

mimeMessage.setContent(multiPart);
mimeMessage.setSentDate(new Date());

Transport transport = mailSession.getTransport("smtp");
transport.connect("mail.myserver.com", null, null);
transport.sendMessage(mimeMessage,
mimeMessage.getAllRecipients());


I know that the version of JavaMail shipping with WebSphere 4 is
older than 1.3.2, and this newer JAR may be unsupported and causing
compatibility issues. To be safe, we'll be reverting back to the out-of-
box configuration when the environment is rebuilt this evening. However,
my gut still tells me there has to be something else in play. Has anyone
else seen this issue before, and/or have any thoughts on what the
solution may be? Thanks in advance!
 
G

Graeme Hill

Hey everybody -

I'm wondering if anyone's ever seen this issue before. I'm sending
plain SMTP emails in a JSP (on WebSphere 4) using JavaMail 1.3.2, and the
messages are being received with no body.

Below is the basic gist of the block of code sending the emails. I
know some things may look funny (specifying the SMTP server address in
Transport.connect() rather than in the Properties object passed to the
Session constructor, etc)... but I had some weird issues getting the app
to resolve to the right mailserver box, and this is the version of code
we came up with that actually results in emails being sent:


Session mailSession =
Session.getDefaultInstance(new Properties();, null);

MimeMessage mimeMessage = new MimeMessage(mailSession);
mimeMessage.setFrom(new InternetAddress("(e-mail address removed)"));
InternetAddress[] address =
InternetAddress.parse("(e-mail address removed)", false);
mimeMessage.setRecipients(Message.RecipientType.TO, address);
mimeMessage.setSubject("Test @ " + new Date().getTime());

MimeBodyPart mimeBodyPart = new MimeBodyPart();
mimeBodyPart.setText("This is a\ntest\n");

Multipart multiPart = new MimeMultipart();
multiPart.addBodyPart(mimeBodyPart);

mimeMessage.setContent(multiPart);
mimeMessage.setSentDate(new Date());

Transport transport = mailSession.getTransport("smtp");
transport.connect("mail.myserver.com", null, null);
transport.sendMessage(mimeMessage,
mimeMessage.getAllRecipients());


I know that the version of JavaMail shipping with WebSphere 4 is
older than 1.3.2, and this newer JAR may be unsupported and causing
compatibility issues. To be safe, we'll be reverting back to the out-of-
box configuration when the environment is rebuilt this evening. However,
my gut still tells me there has to be something else in play. Has anyone
else seen this issue before, and/or have any thoughts on what the
solution may be? Thanks in advance!
I've gone back to some code I did :

Multipart mp = new MimeMultipart();
MimeBodyPart mbp = new MimeBodyPart();
String text = "This is a test";

mbp.setDataHandler(new DataHandler(new ByteArrayDataSource(text, "text/plain")));
mp.addBodyPart(mbp);

The difference is I set a DataHandler [can't remember why !].

One thing I found is that the target email client can cause problems. We
have a java email distribution system at work which normally sends HTML
emails [not my idea I hasten to add] and on Novell Groupwise it comes up
as a blank email or attachment, and on Pegasus, the entire client app
crashes. So I would use a simplistic and reliable client for testing that
won't try and hide bits of the email.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top