Hi,
I'm using
java api mail. i tested gmail. its woring fine. and also am
testing other domain server(testserver.com). its working under same domain(testserver.com to testserver.com).but when i try to send from testserver.com domain server to other domain like gmail or hotmail or yahoo means it showing exection.
here is my code:
try
{
Properties props = System.getProperties();
props.put("mail.smtp.host", "server2.testserver.com");
props.put("mail.debug", "true");
props.put("mail.smtp.user", "test@testserver.com");
props.put("mail.smtp.password", "test");
props.put("mail.smtp.port", "25");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.ssl", "true");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
if (from != null && pword != null)
{
props.put("mail.smtp.auth", "true");
session = Session.getInstance(props,
new MyPasswordAuthenticator(from, pword));
}
else
{
session = Session.getDefaultInstance(props, null);
}
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
InternetAddress toAddress[] = new InternetAddress[to.length];
for(int i = 0; i < to.length; i++)
{
toAddress[i] = new InternetAddress(to[i]);
}
message.setRecipients(javax.mail.Message.RecipientType.TO, toAddress);
message.setSubject(subject);
BodyPart bp1 = new MimeBodyPart();
Multipart multipart = new MimeMultipart();
bp1.setText(messageBody);
multipart.addBodyPart(bp1);
bp1 = new MimeBodyPart();
javax.activation.DataSource source = new FileDataSource(ff);
bp1.setDataHandler(new DataHandler(source));
bp1.setFileName("fileName");
multipart.addBodyPart(bp1);
message.setContent(multipart);
Transport.send(message);
System.out.println("Sucessfully sent");
}
catch(Exception e)
{
System.out.println((new StringBuilder("this is the error: ")).append(e).toString());
return false;
}
//***************
when i try to send gmail or anyother mail server means it showing below exception:
javax.mail.SendFailedException:Sending Failed;
nested exception is:
class javax.mail.MessagingException: Exception reading response;
nested exception is:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
Any one please find the solution.
Thanks in advance,
Vinoth sathiya