tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jacques Desodt <>
Subject In webapp, sending multipart email with Javamail : noname attachment instead of message
Date Tue, 17 Apr 2012 16:45:03 GMT

I try to send a Multipart email in a simple java method, using Javamail.
When i use the method in a local java app, everything is fine.
When i use the same method in a webapp hosted by Tomcat,
i got no message, but a file "noname" in attachment.

Here is the method :

public void sendTestMultipartMail(String host, final String username, final
String password, String from, String to) throws Exception {

Properties properties = System.getProperties();
properties.setProperty("", host);
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.starttls.enable", "true");
properties.put("mail.smtp.port", "587");

Session session = Session.getInstance(properties,
  new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);

Message msg = new MimeMessage(session);

msg.setFrom(new InternetAddress(from));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
msg.setSubject("Test MultiPart Mail");

Multipart multipart = new MimeMultipart();

BodyPart part1 = new MimeBodyPart();
part1.setText("This is multipart mail and u read part1......");

BodyPart part2 = new MimeBodyPart();
part2.setText("This is multipart mail and u read part2......");




And here are the results (i use gmail) :

[image: Images intégrées 1]

The first (and wrong) email came from the Tomcat server.
It has no message, and an attachment with "noname" name.
The other email is good and came from my java app.

Thanks in advance,

  • Unnamed multipart/related (inline, None, 0 bytes)
View raw message