Reputation: 255
I need to send email over smtp with ssl using java client. I'm not sure how to do that.
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
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
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
Reputation: 4363
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
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