Well, a little bit disappointed...
I changed my code :

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

        Properties properties = new Properties();
        properties.put("mail.smtp.host", 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......");

        multipart.addBodyPart(part1);
        multipart.addBodyPart(part2);

        msg.setContent(multipart);

        Transport.send(msg);
    }

-----------------------------------
Here is the raw message, sended by my local java app:

Return-Path: <jdes...@gmail.com>
Received: from Jack-PC (xxx-1-166-xxx.w90-58.xxx.fr. [xx.xx.xx.237])
        by mx.google.com with ESMTPS id
fz9sm35717987wib.3.2012.04.18.09.55.23
        (version=TLSv1/SSLv3 cipher=OTHER);
        Wed, 18 Apr 2012 09:55:24 -0700 (PDT)
Date: Wed, 18 Apr 2012 09:55:24 -0700 (PDT)
From: jdes...@gmail.com To: jdes...@gmail.com
Message-ID: <591786211.01334768140322.JavaMail.e-soa@Jack-PC>
Subject: Test MultiPart Mail
MIME-Version: 1.0

Content-Type: multipart/mixed;
        boundary="----=_Part_0_1395193582.1334768140066"

------=_Part_0_1395193582.1334768140066
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

This is multipart mail and u read part1......
------=_Part_0_1395193582.1334768140066
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

This is multipart mail and u read part2......
------=_Part_0_1395193582.1334768140066--


------------------------------------
and here is the raw message, sended by my webapp via tomcat :

Return-Path: <jdes...@gmail.com>
Received: from Jack-PC (xxx-1-166-xxx.w90-58.xxx.fr. [xx.xx.xx.237])
        by mx.google.com with ESMTPS id e6sm35753185wix.8.2012.04.18.10.00.33
        (version=TLSv1/SSLv3 cipher=OTHER);
        Wed, 18 Apr 2012 10:00:33 -0700 (PDT)
Date: Wed, 18 Apr 2012 10:00:33 -0700 (PDT)
From: jdes...@gmail.com
To: jdes...@gmail.com
Message-ID: <1292444743.1.1334768450071.JavaMail.e-soa@Jack-PC>
Subject: Test MultiPart Mail
MIME-Version: 1.0
Content-Type: multipart/mixed;
        boundary="----=_Part_0_623107838.1334768449974"


... and that's all...
Why ? I don't understand. Same method, same smtp server.
Any idea ?

Jacques



2012/4/18 Jacques Desodt <jdes...@gmail.com>

> Hi Chris,
>
> Thanks a lot for your quick reply !
> My apologies for the image posted, I didn't know
> it could be stripped by the mailing list.
> OK, I will test your solution tonight.
>
> I agree with you, Javamail API is really complicated,
> I always used Apache Commons Email.
> I will have a look at your great project.
>
> Jacques
>
>
> 2012/4/18 Christopher Schultz <ch...@christopherschultz.net>
>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Jacques,
>>
>> On 4/17/12 12:45 PM, Jacques Desodt wrote:
>> > 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.
>>
>> Your code looks reasonable. I wonder if you are missing some system
>> property when running under Tomcat, since you use the system
>> properties as a basis for your JavaMail session setup.
>>
>> Try using an empty Properties object instead of taking
>> System.getProperties() and mutating that. You might find that there is
>> some property available in your standalone environment that you are
>> missing in the Tomcat one.
>>
>> > And here are the results (i use gmail) :
>> >
>> > Images intégrées 1
>>
>> (I'm not sure what that means... if you attached something to your
>> email, it was stripped by the mailing list).
>>
>> > 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.
>>
>> What are the differences when you look at the actual source code of
>> the message? You can learn a lot from looking at the raw MIME message.
>>
>> BTW, if you intend to move from a simple multipart text message as you
>> have above to something more complicated (such as text + HTML +
>> attachments) be aware that the JavaMail API is a complete main in the
>> neck to use. I would highly recommend using a wrapper API such as
>> commons-email or my own emailer wrapper you can find at
>> http://christopherschultz.net/projects/java/
>>
>> I happen to like mine better ;)
>>
>> - -chris
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
>> Comment: GPGTools - http://gpgtools.org
>> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>>
>> iEYEARECAAYFAk+OHRMACgkQ9CaO5/Lv0PDk6wCgtsLID0HPf6nNH2bFc/ThfrTl
>> J58AnjuTcjIFhj1QOgESVmgMFK5jWOBC
>> =QXQU
>> -----END PGP SIGNATURE-----
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
>> For additional commands, e-mail: users-h...@tomcat.apache.org
>>
>>
>

Reply via email to