IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

NetBeans Java Discussion :

J2EE envoie de mail problem sur les fichiers joints


Sujet :

NetBeans Java

  1. #1
    Membre à l'essai
    Inscrit en
    Octobre 2010
    Messages
    44
    Détails du profil
    Informations forums :
    Inscription : Octobre 2010
    Messages : 44
    Points : 23
    Points
    23
    Par défaut J2EE envoie de mail problem sur les fichiers joints
    Bonsoir Tout le monde
    J'ai crée une application web permettant d'envoyé des e mail.
    Quand j'envoie un e mail il arrive a sa destination sans aucun problème .

    si j'ajoute un fichiers a l'e mail (pièce jointe) le contenu arrive a sa destination le nom de fichier aussi mais il se télécharge pas et sa taille est de 0 octet.
    Voila le code source SVP aidez moi c'est urgent

    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
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
     
     
    package jMail;
    import javax.mail.*;
    import javax.mail.internet.*;
    import java.util.*;
    import javax.activation.DataHandler;
    import javax.activation.DataSource;
    import javax.activation.FileDataSource;
     
     
    /**
     *
     * @author Agraj
     */
    public class Mail {
     
    private String to;
    private String from;
    private String message;
    private String subject;
    private String smtpServ;
    private String joindre;
        public Mail(String to, String from, String message, String subject, String smtpServ, String joindre) {
            this.to = to;
            this.from = from;
            this.message = message;
            this.subject = subject;
            this.smtpServ = smtpServ;
            this.joindre = joindre;
        }
     
     
        public String getJoindre() {
            return joindre;
        }
     
        public void setJoindre(String joindre) {
            this.joindre = joindre;
        }
     
        public String getTo() {
            return to;
        }
     
        public void setTo(String to) {
            this.to = to;
        }
     
        public String getFrom() {
            return from;
        }
     
        public void setFrom(String from) {
            this.from = from;
        }
     
        public String getMessage() {
            return message;
        }
     
        public void setMessage(String message) {
            this.message = message;
        }
     
        public String getSubject() {
            return subject;
        }
     
        public void setSubject(String subject) {
            this.subject = subject;
        }
     
        public String getSmtpServ() {
            return smtpServ;
        }
     
        public void setSmtpServ(String smtpServ) {
            this.smtpServ = smtpServ;
        }
     
        public int sendMail(){
            try
            {
                Properties props = System.getProperties();
                  // -- Attaching to default Session, or we could start a new one --
                  props.put("mail.transport.protocol", "smtp");
                  props.put("mail.smtp.starttls.enable","true");
                  props.put("mail.smtp.host",smtpServ);
                  props.put("mail.smtp.auth", "true");
                  Authenticator auth = new SMTPAuthenticator();
                  Session session = Session.getInstance(props,auth);
                  // -- Create a new message --
                  Message msg = new MimeMessage(session);
                  // -- Set the FROM and TO fields --
     
                  msg.setRecipients(Message.RecipientType.TO,
                    InternetAddress.parse(to, false));
     
                   msg.setRecipients(Message.RecipientType.CC,InternetAddress.parse("s.sayahi@hotmail.com", false));
                    msg.setRecipients(Message.RecipientType.BCC,InternetAddress.parse("sayahisalem@live.fr", false));
                  // -- Set the subject and body text --
                  msg.setSubject(subject);
                  msg.setText(message);
                  // -- Set some other header information --
     
                  msg.setHeader("MyMail", "Java Mail Test");
                  msg.setSentDate(new Date());
    msg.setFrom(new InternetAddress(from));
        InternetAddress ADRESSE[]={new InternetAddress("s.sayahi@hotmail.com"),new InternetAddress("sayahisalem@live.fr")};
     
                  msg.addFrom(ADRESSE);
     
                 //   msg.setFileName(to)
     
                    Multipart multipart = new MimeMultipart();
     
        					// creation partie principale du message
        					BodyPart messageBodyPart = new MimeBodyPart();
        					messageBodyPart.setText(message);
        					multipart.addBodyPart(messageBodyPart);
     
    					    // creation et ajout de la piece jointe
        					messageBodyPart = new MimeBodyPart();
        					DataSource source = new FileDataSource("C:\\CientMail.java");
        				      messageBodyPart.setDataHandler(new DataHandler(source));
     
        					messageBodyPart.setFileName("C:\\CientMail.java");
                                           // BodyPart messageBodyPart1 = new MimeBodyPart();
        					messageBodyPart.setText(message);
        					multipart.addBodyPart(messageBodyPart);
     
     
    					    // ajout des ?l?ments au mail
        					msg.setContent(multipart);
                  // -- Send the message --
                  Transport.send(msg);
                  System.out.println("Message sent to"+to+" OK.");
                  return 0;
            }
            catch (Exception ex)
            {
              ex.printStackTrace();
              System.out.println("Exception "+ex);
              return -1;
            }
      }
     
          private class SMTPAuthenticator extends javax.mail.Authenticator {
     
     
            @Override
            public PasswordAuthentication getPasswordAuthentication() {
                String username = "user@mail.com";
                String password = "*******";
                return new PasswordAuthentication(username, password);
            }
      }
    }

  2. #2
    Membre à l'essai
    Inscrit en
    Octobre 2010
    Messages
    44
    Détails du profil
    Informations forums :
    Inscription : Octobre 2010
    Messages : 44
    Points : 23
    Points
    23
    Par défaut
    Citation Envoyé par cesear89 Voir le message
    Bonsoir Tout le monde
    J'ai crée une application web permettant d'envoyé des e mail.
    Quand j'envoie un e mail il arrive a sa destination sans aucun problème .

    si j'ajoute un fichiers a l'e mail (pièce jointe) le contenu arrive a sa destination le nom de fichier aussi mais il se télécharge pas et sa taille est de 0 octet.
    Voila le code source SVP aidez moi c'est urgent

    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
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
     
     
    package jMail;
    import javax.mail.*;
    import javax.mail.internet.*;
    import java.util.*;
    import javax.activation.DataHandler;
    import javax.activation.DataSource;
    import javax.activation.FileDataSource;
     
     
    /**
     *
     * @author Agraj
     */
    public class Mail {
     
    private String to;
    private String from;
    private String message;
    private String subject;
    private String smtpServ;
    private String joindre;
        public Mail(String to, String from, String message, String subject, String smtpServ, String joindre) {
            this.to = to;
            this.from = from;
            this.message = message;
            this.subject = subject;
            this.smtpServ = smtpServ;
            this.joindre = joindre;
        }
     
     
        public String getJoindre() {
            return joindre;
        }
     
        public void setJoindre(String joindre) {
            this.joindre = joindre;
        }
     
        public String getTo() {
            return to;
        }
     
        public void setTo(String to) {
            this.to = to;
        }
     
        public String getFrom() {
            return from;
        }
     
        public void setFrom(String from) {
            this.from = from;
        }
     
        public String getMessage() {
            return message;
        }
     
        public void setMessage(String message) {
            this.message = message;
        }
     
        public String getSubject() {
            return subject;
        }
     
        public void setSubject(String subject) {
            this.subject = subject;
        }
     
        public String getSmtpServ() {
            return smtpServ;
        }
     
        public void setSmtpServ(String smtpServ) {
            this.smtpServ = smtpServ;
        }
     
        public int sendMail(){
            try
            {
                Properties props = System.getProperties();
                  // -- Attaching to default Session, or we could start a new one --
                  props.put("mail.transport.protocol", "smtp");
                  props.put("mail.smtp.starttls.enable","true");
                  props.put("mail.smtp.host",smtpServ);
                  props.put("mail.smtp.auth", "true");
                  Authenticator auth = new SMTPAuthenticator();
                  Session session = Session.getInstance(props,auth);
                  // -- Create a new message --
                  Message msg = new MimeMessage(session);
                  // -- Set the FROM and TO fields --
     
                  msg.setRecipients(Message.RecipientType.TO,
                    InternetAddress.parse(to, false));
     
                   msg.setRecipients(Message.RecipientType.CC,InternetAddress.parse("s.sayahi@hotmail.com", false));
                    msg.setRecipients(Message.RecipientType.BCC,InternetAddress.parse("sayahisalem@live.fr", false));
                  // -- Set the subject and body text --
                  msg.setSubject(subject);
                  msg.setText(message);
                  // -- Set some other header information --
     
                  msg.setHeader("MyMail", "Java Mail Test");
                  msg.setSentDate(new Date());
    msg.setFrom(new InternetAddress(from));
        InternetAddress ADRESSE[]={new InternetAddress("s.sayahi@hotmail.com"),new InternetAddress("sayahisalem@live.fr")};
     
                  msg.addFrom(ADRESSE);
     
                 //   msg.setFileName(to)
     
                    Multipart multipart = new MimeMultipart();
     
        					// creation partie principale du message
        					BodyPart messageBodyPart = new MimeBodyPart();
        					messageBodyPart.setText(message);
        					multipart.addBodyPart(messageBodyPart);
     
    					    // creation et ajout de la piece jointe
        					messageBodyPart = new MimeBodyPart();
        					DataSource source = new FileDataSource("C:\\CientMail.java");
        				      messageBodyPart.setDataHandler(new DataHandler(source));
     
        					messageBodyPart.setFileName("C:\\CientMail.java");
                                           // BodyPart messageBodyPart1 = new MimeBodyPart();
        					messageBodyPart.setText(message);
        					multipart.addBodyPart(messageBodyPart);
     
     
    					    // ajout des ?l?ments au mail
        					msg.setContent(multipart);
                  // -- Send the message --
                  Transport.send(msg);
                  System.out.println("Message sent to"+to+" OK.");
                  return 0;
            }
            catch (Exception ex)
            {
              ex.printStackTrace();
              System.out.println("Exception "+ex);
              return -1;
            }
      }
     
          private class SMTPAuthenticator extends javax.mail.Authenticator {
     
     
            @Override
            public PasswordAuthentication getPasswordAuthentication() {
                String username = "user@mail.com";
                String password = "*******";
                return new PasswordAuthentication(username, password);
            }
      }
    }
    Pas de solution ??

Discussions similaires

  1. Probleme sur les fichiers (fonction fread)
    Par anoir dsr dans le forum C
    Réponses: 7
    Dernier message: 27/01/2011, 14h31
  2. probleme de lien sur les fichiers swf
    Par phlip1 dans le forum Dreamweaver
    Réponses: 2
    Dernier message: 29/08/2007, 09h27
  3. Probleme sur les chaines de caractere
    Par scorpiwolf dans le forum C
    Réponses: 8
    Dernier message: 06/05/2002, 19h01

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo