2010-06-02 5 views
1

J'ai une application qui envoie des confirmations par e-mail. La partie email utilise Commons Mail API. Le code simple qui fait l'envoi de courrier est comme indiqué ci-dessous;La pièce jointe Java ne fonctionne pas sur Tomcat

import org.apache.commons.mail.*; 
... 
// Create the attachment 
EmailAttachment attachment = new EmailAttachment(); 
attachment.setURL(new URL("http://cashew.org/doc.pdf")); 
attachment.setDisposition(EmailAttachment.ATTACHMENT); 
attachment.setDescription("Testing attach"); 
attachment.setName("doc.pdf"); 

// Create the email message 
MultiPartEmail email = new MultiPartEmail(); 
email.setHostName("mail.cashew.com"); 
email.addTo("[email protected]"); 
email.setFrom("[email protected]"); 
email.setSubject("Testing); 
email.setMsg("testing message"); 

// add the attachment 
email.attach(attachment); 

// send the email 
email.send(); 

Mon problème est, quand j'exécute cette application depuis Eclipse, je reçois e-mail envoyé avec pièce jointe sans aucun problème. Mais quand je déploie l'application sur le serveur Tomcat (j'ai

essayé les deux version 5 & 6 no joy), l'e-mail est envoyé avec le contenu ci-dessous;

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

testing 


Regards, 

los 

------=_Part_0_25002283.1275298567928 
Content-Type: application/pdf; name="doc.pdf" 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment; 
filename="doc.pdf" 
Content-Description: Testing attach 

JVBERi0xLjQNJeLjz9MNCjYzIDAgb2JqDTw8L0xpbmVhcml6ZWQgMS9MIDMxMzE4Mi9PIDY1L0Ug 
Mjg2NjY5L04gMS9UIDMxMTgwMi9IIFsgMjgzNiAzNzZdPj4NZW5kb2JqDSAgICAgICAgICAgICAg 
DQp4cmVmDQo2MyAxMjcNCjAwMDAwMDAwMTYgMDAwMDAgbg0KMDAwMDAwMzM4MCAwMDAwMCBuDQow 
MDAwMDAzNTIzIDAwMDAwIG4NCjAwMDAwMDQzMDcgMDAwMDAgbg0KMDAwMDAwNTEwOSAwMDAwMCBu 
DQowMDAwMDA2Mjc5IDAwMDAwIG4NCjAwMDAwMDY0MTAgMDAwMDAgbg0KMDAwMDAwNjU0NiAwMDAw 
MCBuDQowMDAwMDA3OTY3IDAwMDAwIG4NCjAwMDAwMDkwMjMgMDAwMDAgbg0KMDAwMDAwOTk0OSAw 
MDAwMCBuDQowMDAwMDExMDAwIDAwMDAwIG4NCjAwMDAwMTIwNTkgMDAwMDAgbg0KMDAwMDAxMjky 
MCAwMDAwMCBuDQowMDAwMDEyOTU0IDAwMDAwIG4NCjAwMDAwMTI5ODIgMDAwMDAgbg0KMDAwMDAx 
....... 
CnN0YXJ0eHJlZg0KMTE2DQolJUVPRg0K 
------=_Part_0_25002283.1275298567928-- 

Une chose que j'ai également remarquée est que les informations d'en-tête ne montrent pas les valeurs TO et Subject. Hmm joli wierd. Je dois préciser que, ci-dessus n'est pas généré de DEBUG, c'est le message reçu dans mon client Outlook.

Quelqu'un peut-il m'aider s'il vous plaît!

Mise à jour: L'application est assez simple. Joindre une partie et un message texte en tant que partie séparée également.

public final void Email(String from, String to, String cc, 
      String subject, String message, String doc, String bcc) { 

     MultiPartEmail email = new MultiPartEmail(); 

    try { 

     if (!(doc == null)) { 
        EmailAttachment attachment = new EmailAttachment(); 
        attachment.setURL(new URL("http://cashew.org/doc.pdf")); 
     attachment.setDisposition(EmailAttachment.ATTACHMENT); 
     attachment.setDescription("Testing attach"); 
     attachment.setName("doc.pdf"); 
        email.attach(attachment); 
     } 


     email.setHostName("mail.cashew.com"); 

     // [ Set Header details 
     email.setTo(getAddress(to)); 
     email.setFrom(from); 
     email.setSubject(subject); 


     if (!(cc == null)) { 
       eEmail.setCc(getAddress(cc)); 
     } 

     if (!(bcc == null)) { 
      email.setBcc(getAddress(bcc)); 
     } 

     email.setMsg(message); 

     email.send(); 


    } catch (Exception ex) { 
     ex.printStackTrace(); 
    } 
} 

Est-ce que quelqu'un sait ce qui se passe?

+0

Je ne pense pas que vous nous montriez tout. Par exemple, je ne vois pas de code pour la première partie de votre message en plusieurs parties. –

+0

@Alexander - méthode pour effectuer l'envoi d'e-mail montré ci-dessus. – Bitmap

Répondre

0

This was the issue

Causes: Le problème décrit est causée par les dépendances transitif de Apache CXF 2 ou Axiom.

SOLUTION: Pour résoudre ce problème, exclure geronimo-javamail_1.4_spec de la construction, et juste compter sur le courrier-1.4.x.jar de javax.

<!--For Apache CXF 2 Project: Do this Exclude--> 
<dependency>  
    <groupid>org.apache.cxf</groupid> 
    <artifactid>cxf-rt-frontend-jaxws</artifactid>  
    <version>2.2.6</version>  
    <exclusions>   
     <exclusion>    
     <groupid>org.apache.geronimo.specs</groupid>    
     <artifactid>geronimo-javamail_1.4_spec</artifactid>   
     </exclusion> 
    <exclusion> 
     <groupid>org.apache.geronimo.specs</groupid> 
     <artifactid>geronimo-activation_1.1_spec</artifactid> 
    </exclusion>  
</exclusions> 
</dependency> 

<!--For Axis2 Project with Axiom Dependency: Do this Exclude--> 
<dependency> 
    <groupid>org.apache.ws.commons.axiom</groupid> 
    <artifactid>axiom-api</artifactid> 
    <version>1.2.8</version> 
    <exclusions>  
    <exclusion> 
     <groupid>org.apache.geronimo.specs</groupid> 
     <artifactid>geronimo-activation_1.1_spec</artifactid> 
    </exclusion> 
    <exclusion> 
     <groupid>org.apache.geronimo.specs</groupid> 
     <artifactid>geronimo-javamail_1.4_spec</artifactid> 
    </exclusion> 
    </exclusions> 
</dependency>