Friday, December 30, 2011

JavaMail

I am using JavaMail to try to send mail.

I am using smtp as the protocol.

I had to add authentication for the connection.

if (mailhost != null)
props.put("mail." + prot + ".host", mailhost);
if (auth) {
props.put("mail.smtp.starttls.enable","true");
props.put("mail." + prot + ".auth", "true");
}

I had to use the keytool program to add a certificate for the server. The easiest way was to open the server authentication in Thunderbird and export the certificate, then use the keytool to import the certificate to the cacerts file.

\Program Files (x86)\Java\jdk1.6.0_20\jre\bin\keytool" -import -file c:\Users\me\server.com.crt -alias myHost -keystore ..\lib\security\cacerts

This worked for one of my mail servers, but did not work for my school server. The error I received was:

ADDRESS FAILED:
com.sun.mail.smtp.SMTPAddressFailedException: 554 : Relay access denied

After reading online, it dawned on me that I cannot use the mail server when I am not on the domain. I connected to the domain with a VPN and the mail was sent.

My third domain still does not authenticate. I have followed the steps for the other two, but I am still receiving the error that a certificate cannot be found. The strange thing is that this is the server for the ISP that I am using to connect to the internet. Maybe I don't need authentication? BINGO!!! It worked without authentication.

No comments:

Post a Comment

Followers