-
-
Notifications
You must be signed in to change notification settings - Fork 271
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add optional support for Dkim signing #33
Comments
? |
I saw a log: public final void sendDKIMMail(final Email email) throws MailException {
if (validate(email)) {
try {
// fill and send wrapped mime message parts
Message message = produceMimeMessage(email, getSession());
convertToDKIMMessage(message, ...);
message.saveChanges(); // some headers and id's will be set for this specific message
Transport transport = getSession().getTransport();
try {
transport.connect();
transport.sendMessage(message, message.getAllRecipients());
} finally {
transport.close();
}
} catch (final UnsupportedEncodingException e) {
logger.error(e.getMessage(), e);
throw new MailException(String.format("Encoding not accepted: %s", e.getMessage()), e);
} catch (final MessagingException e) {
logger.error(e.getMessage(), e);
throw new MailException(String.format("Generic error: %s", e.getMessage()), e);
}
}
} |
Ahh, alright. Perhaps Btw, what is convertToDKIMMessage? Is that something this library might benefit from? |
convertToDKIMMessage is a function to add DKIM signature to mail. I am using https://github.com/markenwerk/java-utils-mail-dkim to help me do this. I think it is good to add this to simple-java-mail. |
Will you share your implementation? I'm not really familiar with DKIM. |
What about this, @chaopeng:
Which throws an exception if |
Thank you @bbottema . maybe the method also support byte[]/String as key is better. |
@chaopeng, what would be the content of that? Would it be the key itself, or a filepath to the key? |
the string/ byte[] will be the key. |
Found this library as well: https://github.com/usrflo/DKIM-for-JavaMail /edit: I just noticed that your reference is actually a fork on this one. I'm not sure which would be better, but the fork has been updated more recently. |
Yes the one I use is fork on https://github.com/usrflo/DKIM-for-JavaMail . I use https://github.com/markenwerk/java-utils-mail-dkim is because DKIM-for-JavaMail is not in any public maven repo and no activity for many years. |
@chaopeng, I made some changes, but I don't know how to test this easily. Do you have a domain with selector and a sample key for me which I can use to test with? |
@bbottema do you have domain? If yes you can use this script to generate a key. And selector will be 'test'
If you dont I can setup my domain and pm you the key for temporary test. |
Hi @chaopeng, I committed my changes into the branch "DKIM". I already verified the initial stage of creating the dkim signer and parsing the private DER key works properly, but I have yet to test the actual sending and verification of the domain record that happens during If you checkout the branch DKIM, you can try it if you want. See Right now I'm out of time, but I might try adding a DNS TXT record to my Amazon AWS domain in the weekend and see if everything works. In the meantime, maybe you have the time to try it out. |
I did some testing with my own domain and it's going quite well, actually, up to the point where the email is being signed (after successfully getting the domain record). When signing the email's content, I get an error:
It might be because I took a random dummy private key from the internet, but I think it was a 2048 bytes encrypted key instead of 1024. I'll run a test with a key from your script. |
Ok, cool. It works. This is what gmail received:
So DKIM is fully operational. I'll merge it to the trunk and do a release. |
Released in v3.1.0. |
extends Mailer to add sendDKIMMail()
The text was updated successfully, but these errors were encountered: