I have few questions. Let me being like this.
I wanted to write code to send email using JavaMail API. I searched internet and found some good examples.
I picked one and modified it a bit. Here is the code:
This code worked as-is when I used it with GMail's SMTP server ("smtp.gmail.com").
When I changed the code (smtp_host_name, smtp_port properties and authentication UserID/Pwd) to send email through the SMTP server of my ISP provider, this code failed with following error:
After a bit of struggle, I found that if I comment out following line, code worked just fine:
Can anyone shed some light what caused this error?
What is the effect of following line in above code (highlighted in bold above):
And on another site (java-email-example), I found following line of code (instead of the one I have listed above):
What is the effect of this line on the functionality of the code (and/or SMTP server being used) and how is it different from the line I listed just above?
When I do not provide following properties, the code (given at the top) still works:
Are these optional or what?
I am not sure how to phrase this question but here I go: Should I use SSL or not? Does SSL make the emails being sent secure (encrypted)?
In all likelihood, nothing at all. It was necessary years ago, when the JDK didn't by default ship with SSL enabled. But ever since Java 1.4 (I think) the standard JDK knows about SSL, and the Sun SSL provider is already enabled. (If you search through your JDK installation for a file called "java.security" you'll see how that works.)
The easy way to find out what these do is to leave them out and observe what happens. You may want to leave "mail.debug" in until last, because that causes all that debugging output to be generated. I'm surprised that it still works if "mail.smtp.auth" is removed - usually that's required to turn on authentication.
Should I use SSL or not? Does SSL make the emails being sent secure (encrypted)?
SSL is used only for the connection to your mail provider (Google in this case). If you want to secure the transfer of the email, then SSL is useful. But it does not encrypt the email while it's stored at your provider, or on its way from your provider to the recipient's provider, or from the recipient's provider to the recipient.
You should use it if you don't trust your network or your ISP provider. But it you want the message contents to be safe from snooping by everybody, then you need to use PGP/GPG or S/MIME.
Ping & DNS - updated with new look and Ping home screen widget
Joined: Jan 20, 2004
Thank you so much Ulf for your time and the detailed response to answer my questions.