onjour,

J'ai un problème pour envoyer un mail avec du text et une piece joint à partir d'un WEB SERVICE.

Ma classe a une fonction sendMsgAttachement qui envoie un mail avec une piece joint et du text. Cette fonctionnalité fonctionne trés dans un environnement local c'est à dire lors que je l'exécute avec un void main mais lorsque j'ai transformé ma classe en WEB SERVICE (AXIS) je reçois des mail avec le contenu vide. Merci de votre aide.

Voici la fct:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
 
private boolean sendMsgAttachFile(String _to, String _subject, String _bodyText, String _fileName, int iddoc) {
  Properties props = new Properties();
  props.setProperty("mail.smtp.host", smtp);
 
  if (elogin != null && epass != null )
  {
    elogin.trim();
    epass.trim();
    //props.setProperty("mail.smtp.auth", "true");
    //Authenticator auth = new SMTPAuthenticator();
    //session = Session.getDefaultInstance(props, auth);
    session = Session.getDefaultInstance(props,null);
  } else {
     session = Session.getDefaultInstance(props,null);
  }
  try {
     File path_name = new File(RepCryptFile + _fileName);
     if (path_name.exists()) {
    Message msg = new MimeMessage(session);
    msg.setFrom(new InternetAddress(emaildefault));
        InternetAddress[] address ={new InternetAddress(_to)};
    msg.setRecipients(Message.RecipientType.TO, address);
        msg.setSubject(_subject);
        MimeBodyPart textPart = new MimeBodyPart();
               //textPart.setHeader("Content-Transfert-Encoding", "8Bit");
        textPart.setText(_bodyText);
        MimeBodyPart attachFilePart = new MimeBodyPart();
    FileDataSource fds = new FileDataSource(RepCryptFile + _fileName);
        attachFilePart.setDataHandler(new DataHandler(fds));
 
    String name = selectnameoffile(Integer.toString(iddoc));
        attachFilePart.setFileName(name);
    Multipart mp = new MimeMultipart();
    mp.addBodyPart(textPart);
    mp.addBodyPart(attachFilePart);
    msg.setContent(mp);
    Transport.send(msg);
    logger.info("The email is sent with file: " + name
+ " mess: " + _bodyText + "file protect: " + RepCryptFile + _fileName);
      } else {
        logger.info("Error Send Mail: The email not send \n The file doesn't exit");
    return false;
      }
 
     } catch(MessagingException ex) {
                logger.fatal("Error Send Mail: ", ex);
                return false;
        } catch(Exception err) {
            logger.fatal("Error Send Mail: ", err);
            return false;
        }
        return true;
 }