postMail method does not work
postMail method throws this exception "Could not send email". This exception occurs at this line of code "Transport.send(msg)". Does anyone have any idea ?
publicvoid postMail( String recipients[ ], String subject,
String message , String from)throws MessagingException,IOException
{
boolean debug =false;
//Set the host smtp address
Properties props =new Properties();
props.put("mail.smtp.host", smtpHostName);// smtpHostName = "mail.isentric.com"
props.put("mail.smtp.auth","true");
Authenticator auth =new SMTPAuthenticator();
Session session = Session.getDefaultInstance(props, auth);
session.setDebug(debug);
// create a message
Message msg =new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom =new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo =new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] =new InternetAddress(recipients[i]);
System.out.println("Attempting to send email to: " + recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message,"text/plain");
Transport.send(msg);// Error : Unable to send
System.out.println("Successfully sent mail to all in list");
}

