Bonjour,
j'essaie de crypté un mail.
mais j'ai une erreur qui empêche l'envoi du message (Transport.send()).
L'erreur est la suivante :
L'idée du mail est la suivante.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 javax.mail.MessagingException: IOException while sending message; nested exception is: javax.activation.UnsupportedDataTypeException: no object DCH for MIME type Application/EDI-consent at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:676)
Je crée un mail normal, avec une pièce jointe et certains paramètres bien précis :
ensuite j'encrypte ce message :
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 public MimeMessage getMessage(string monfichiertemp) { MimeBodyPart attachment = new MimeBodyPart(); DataSource source = new FileDataSource(monfichiertemp); attachment.setDataHandler(new DataHandler(source)); attachment.setFileName("monfichier"); attachment.setDescription(description); attachment.setHeader("Content-Transfer-Encoding", "BASE64"); attachment.setHeader("Content-Type", "Application/EDI-consent"); MimeMessage body = new MimeMessage(session); body.setSubject("sujet du message"); body.setContent(attachment); body.setFrom(new InternetAddress("moi@free.fr")); body.addRecipient(Message.RecipientType.TO, new InternetAddress("moi@free.fr")); body.addRecipient(Message.RecipientType.BCC, new InternetAddress("moi@gmail.com")); body.saveChanges(); return body; }
et enfin, cette nouvelle "pièce jointe" cryptée, je la joint a mon mail que je veux envoyer :
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 protected MimeBodyPart getSSMimeMessage(MimeMessage mimeMessage, X509Certificate certificate) { MimeBodyPart bodyPart = null; try { SMIMEEnvelopedGenerator gen = new SMIMEEnvelopedGenerator(); gen.addKeyTransRecipient(certificate); bodyPart = gen.generate(mimeMessage, SMIMEEnvelopedGenerator.DES_EDE3_CBC, 128, "BC"); } catch (NoSuchAlgorithmException noSuchAlgorithm) { noSuchAlgorithm.printStackTrace(); } catch (NoSuchProviderException noSuchProvider) { noSuchProvider.printStackTrace(); } catch (SMIMEException smime) { smime.printStackTrace(); } return bodyPart; }
et donc, lors du "send", paf erreur.
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 //1ERE VERSION //------------ private void sendMimeMessage(String subject, MimeBodyPart bodypart) throws MessagingException, AddressException, IOException { MimeMessage body = new MimeMessage(session); body.setFrom(new InternetAddress("moi@free.fr")); body.addRecipient(Message.RecipientType.TO, new InternetAddress("moi@free.fr")); body.addRecipient(Message.RecipientType.BCC, new InternetAddress("moi@gmail.com")); body.setSubject(subject); body.setContent(bodypart.getContent(), bodypart.getContentType()); body.saveChanges(); Transport.send(body); }
bon, en cherchant un peu, si je construit mon dernier mail de cette manière :
la ca marche, mais mon destinataire n'arrive pas a décrypter mon message.
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 //2EME VERSION //------------ private void sendMimeMessage(String subject, MimeBodyPart bodypart) throws MessagingException, AddressException, IOException { MimeMultipart multipart = new MimeMultipart(); multipart.addBodyPart(bodypart); MimeMessage body = new MimeMessage(session); body.setFrom(new InternetAddress("moi@free.fr")); body.addRecipient(Message.RecipientType.TO, new InternetAddress("moi@free.fr")); body.addRecipient(Message.RecipientType.BCC, new InternetAddress("moi@gmail.com")); body.setSubject(subject); body.setContent(multipart); body.saveChanges(); Transport.send(body); }
et la première version est tiré des exemples "beg-crypto-examples" qui sont fournis avec BouncyCastle (je crois)
avez vous une idée pour que ma première version du mail soit envoyée sans soucis ?
Merci d'avance
Partager