[ http://issues.apache.org/jira/browse/GERONIMO-1797?page=all ]
Rick McGuire updated GERONIMO-1797:
-----------------------------------
Description:
Mail sent with attachments are not getting the headers set properly, so the
attachment is not recognized by mail clients as being attachment data. The
following short program illustrates this:
//compiles against geronimo j2ee spec jar
import java.io.PrintWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import java.util.Properties;
public class xx {
public static void main (String [] args)
throws IOException, AddressException, NoSuchProviderException,
MessagingException
{
String username = "rickmcg";
String password = "stenos";
String smtphost = "smtp.gmail.com";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.port", "587");
Session session = Session.getDefaultInstance(props);
session.setDebug(true);
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("[EMAIL PROTECTED]"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("[EMAIL PROTECTED]"));
message.setSubject("test subject");
message.setText("test message");
BodyPart messageBodyPart1 = new MimeBodyPart();
messageBodyPart1.setText("part 1");
BodyPart messageBodyPart2 = new MimeBodyPart();
DataSource dataSource = new FileDataSource("xx.java");
messageBodyPart2.setDataHandler(new DataHandler(dataSource));
messageBodyPart2.setFileName("xx.java");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart1);
multipart.addBodyPart(messageBodyPart2);
message.setContent(multipart);
//choose A or B
//A
//===>>> geronimo fails SILENTLY on following line (no message is received)
//===>>> but sun jars work fine
// Transport.send(message);
//B
//===>>> if the classpath contains the sequence: geronimo-mail-jar,
activation-jar
//===>>> then the following lines error out complaining about can't find
"smtp"
//===>>> if the classpath contains the sequence: geronimo-mail-jar,
sun-mail-jar, activation-jar
//===>>> then the following lines work but the parts are all messed up (show
up as one big chunk)
//===>>> if the classpath contains the sequence: sun-mail-jar, activation-jar
//===>>> then the following lines work perfectly fine
Transport transport = session.getTransport("smtp");
transport.connect(smtphost, 587, username, password);
System.out.println("Sending message");
transport.sendMessage(message, InternetAddress.parse("[EMAIL
PROTECTED]"));
transport.close();
}
}
There are multiple problems with the written out headers:
1) No MIME-Version header is getting set.
was:Mail sent with attachments are not getting the headers set properly, so
the attachment is not recognized by mail clients as being attachment data. The
following
> Mail attachments are not getting recognized as MIME parts
> ---------------------------------------------------------
>
> Key: GERONIMO-1797
> URL: http://issues.apache.org/jira/browse/GERONIMO-1797
> Project: Geronimo
> Type: Bug
> Components: mail
> Reporter: Rick McGuire
> Fix For: 1.2
>
> Mail sent with attachments are not getting the headers set properly, so the
> attachment is not recognized by mail clients as being attachment data. The
> following short program illustrates this:
> //compiles against geronimo j2ee spec jar
> import java.io.PrintWriter;
> import java.io.FileReader;
> import java.io.FileWriter;
> import java.io.IOException;
> import javax.mail.*;
> import javax.mail.internet.*;
> import javax.activation.DataHandler;
> import javax.activation.DataSource;
> import javax.activation.FileDataSource;
> import java.util.Properties;
> public class xx {
> public static void main (String [] args)
> throws IOException, AddressException, NoSuchProviderException,
> MessagingException
> {
> String username = "rickmcg";
> String password = "stenos";
> String smtphost = "smtp.gmail.com";
> Properties props = new Properties();
> props.put("mail.smtp.auth", "true");
> props.put("mail.debug", "true");
> props.put("mail.smtp.starttls.enable", "true");
> props.put("mail.smtp.port", "587");
> Session session = Session.getDefaultInstance(props);
> session.setDebug(true);
> Message message = new MimeMessage(session);
> message.setFrom(new InternetAddress("[EMAIL PROTECTED]"));
> message.setRecipients(Message.RecipientType.TO,
> InternetAddress.parse("[EMAIL PROTECTED]"));
> message.setSubject("test subject");
> message.setText("test message");
> BodyPart messageBodyPart1 = new MimeBodyPart();
> messageBodyPart1.setText("part 1");
> BodyPart messageBodyPart2 = new MimeBodyPart();
> DataSource dataSource = new FileDataSource("xx.java");
> messageBodyPart2.setDataHandler(new DataHandler(dataSource));
> messageBodyPart2.setFileName("xx.java");
> Multipart multipart = new MimeMultipart();
> multipart.addBodyPart(messageBodyPart1);
> multipart.addBodyPart(messageBodyPart2);
> message.setContent(multipart);
> //choose A or B
> //A
> //===>>> geronimo fails SILENTLY on following line (no message is received)
> //===>>> but sun jars work fine
> // Transport.send(message);
> //B
> //===>>> if the classpath contains the sequence: geronimo-mail-jar,
> activation-jar
> //===>>> then the following lines error out complaining about can't find
> "smtp"
> //===>>> if the classpath contains the sequence: geronimo-mail-jar,
> sun-mail-jar, activation-jar
> //===>>> then the following lines work but the parts are all messed up
> (show up as one big chunk)
> //===>>> if the classpath contains the sequence: sun-mail-jar, activation-jar
> //===>>> then the following lines work perfectly fine
> Transport transport = session.getTransport("smtp");
> transport.connect(smtphost, 587, username, password);
> System.out.println("Sending message");
> transport.sendMessage(message, InternetAddress.parse("[EMAIL
> PROTECTED]"));
> transport.close();
> }
> }
> There are multiple problems with the written out headers:
> 1) No MIME-Version header is getting set.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira