views:

575

answers:

3

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?

+1  A: 

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.

Brian Agnew
I prefer not to use javamail, only the java 1.6 api
Ido
A: 
  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).

Andrew Strong
I know that the client do not need its own certificate, it needs the server certificate. I was not sure how to get the server certificate in java code, and configure the SMTP/SSL to use the server certificate to open the SSL connection.
Ido
A: 

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

Jady