Ido
Ido

Reputation: 255

How do I send email over SMTP with SSL using Java client?

I need to send email over smtp with ssl using java client. I'm not sure how to do that.

  1. If I have my server certificate installed on my Windows machine, how do I use it?
  2. If I want it to work on a non-Windows machine, do I need to get the certificates in a different way?

BTW: If the SMTP server that I use is using SSL, can I be sure that it will send the mail to the recipient using SSL?

Upvotes: 0

Views: 9924

Answers (4)

retromuz
retromuz

Reputation: 799

Hope this will help you in setting up the server certificate to be trusted by your java client code.

STORE=/path/to/JRE/cacerts
keytool -import -trustcacerts -keystore $STORE -storepass changeit -noprompt -file mymailserver.pem -alias mymailserver

Please use backslashes instead of above forwards slashes (windows guys have confused themselves in path identifiers LOL).

Reference: http://vafer.org/blog/20061010073725/

Upvotes: 0

Jady
Jady

Reputation: 1

You can use MailReporter also. It supports SSL and TLS! http://magithou.com/tips-a-tricks/42-setup-e-mail-accounts/81-ssl-support.htm

Upvotes: 0

Andrew Strong
Andrew Strong

Reputation: 4363

  1. To simply act as a client to an SSL server you do not need your own certificate.
  2. It's no different on non-Windows machines, especially when using Java.

The one thing you may have to do is to tell your Java client to trust the server's certificate.

Your SSL connection to the SMTP server is puerly point-to-point. There's absolutely no guarantee that it will connect to other clients and servers over SSL (unless you control the server).

Upvotes: 0

Brian Agnew
Brian Agnew

Reputation: 272207

Take a look at this tutorial, which details using JavaMail with JSSE (the secure socket extension) and certificate installation.

If you don't want to use JavaMail, you can implement the SMTP protocol yourself over TCP sockets. See here. But you'll be reimplementing a lot of work which at first sight seems trivial, but will have numerous edge cases and complexities. I would strongly recommend using the APIs for the job.

Upvotes: 1

Related Questions