Comments (5)
Try calling message.saveChanges()
after signing.
from java-utils-mail-smime.
If you are referring to the ability to specify the encryption algorithm, I do have a fork that I will be pushing my changes to soon. You can see it at https://github.com/vnomics/java-utils-mail-smime under the variable-encryption-algorithms branch once I've pushed it.
As for the problem I was having with the text attachment, this is an example snippet of how to make the canonicalization safe for the inbound email message:
BodyPart attachmentBody = new MimeBodyPart();
attachmentBody.setDataHandler(new DataHandler(new ByteArrayDataSource(attachment, MediaType.TEXT_PLAIN_VALUE)));
attachmentBody.setHeader( "Content-Transfer-Encoding", "base64" );
attachmentBody.setFileName(attachmentName);
multipart.addBodyPart(attachmentBody);
Setting the Content-Transfer-Encoding
after setting the DataHandler resulted in the rendered email body containing Base64 output wrapped every 76 characters and delimited with "\r\n".
from java-utils-mail-smime.
@matlik Thanks very much for your post. i was using this library and having some strange behavior and though it was just my own problem.
Is it possible to publish your work and I could sync it.
Very much appreciate.
from java-utils-mail-smime.
@matlik you are the life saver. I have the encryption part working as expected now. But looks like still have issue with sign. i have a simple sign function that to send out email but looks like not work as expected:
String from ="[email protected]", to="[email protected]", subject = "sbj", body="body";
javax.mail.Session mailSession = javax.mail.Session.getInstance(new Properties(), null);
MimeMessage message = new MimeMessage(mailSession);
message.setFrom(new InternetAddress(from));
message.setRecipient(RecipientType.TO, new InternetAddress(to));
message.setSubject(subject);
// message.setContent(body, "text/plain; charset=utf-8"); // neither works.
message.setText(body);
System.out.println(SmimeUtil.getStatus(message));
SmimeKey privateKey = getSmimeKey();
message = SmimeUtil.sign(mailSession, message, privateKey);
System.out.println(SmimeUtil.getStatus(message));
System.out.println("-----------------");
And result
NEITHER
NEITHER
-----------------
I added JCE to JDK, and used the certificate that is generated from COMODO. Because the Encryption works, I think the SmimeKey should be generated right. But just did not figure out why the sign fails.
from java-utils-mail-smime.
Another observation:
I need to do following to get signed message sent out
msg = SmimeUtil.sign(mailSession, msg, getSmimeKey());
msg.setContent((Multipart) msg.getContent());
msg.saveChanges();
Otherwise, I will get
java.io.IOException: "text/plain" DataContentHandler requires String object, was given object of type class javax.mail.internet.MimeMultipart
at javax.mail.Transport.send0(Transport.java:218)
at javax.mail.Transport.send(Transport.java:80)
The https://github.com/vnomics/java-utils-mail-smime version handled it way much better. Hope those change would be push to maven.
from java-utils-mail-smime.
Related Issues (5)
- unknown object in getInstance: org.bouncycastle.asn1.DERApplicationSpecific
- SmimeUtil is missing the API to return the "Signed by <from-address>", which email clients generally display HOT 1
- getStatus doesn't determine the S/MIME status correctly according to RFC HOT 1
- How to combine smime with SMTPMessage? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from java-utils-mail-smime.