G
GaryM
Hi all,
I'm trying to utilize the JavaMail package and I've realized a class.
This is the constructor's code:
I am not sure why you are getting the exception. You have got it pretty
much right; however, I am doubtful of the way you are obtaining the
transport. Try the following code changes, which use the destination
address to automatically select the appropriate provider. If it still
does not work then it points to a classpath issue, however if mail.jar
is in the path, I don't see how it could be ...
// InternetAddress to = new InternetAddress("TO_ADDRESS");public sendMail() throws AddressException, MessagingException {
String smtpServer = new String("mail.tin.it");
String userId = new String("USERID");
String password = new String("PASSWORD");
Properties props = new Properties();
props.put("mail.smtp.host", smtpServer);
props.put("mail.smtp.auth","true");
Session session = Session.getDefaultInstance(props, null);
Address to = new InternetAddress("TO_ADDRESS");
InternetAddress from = new InternetAddress("FROM_ADDRESS");
Message message= new MimeMessage(session);
message.setFrom(from);
message.setRecipient(Message.RecipientType.TO, to);
message.setSubject("Test JavaMail");
message.setContent("Ciao Mondo","text/plain");
// just for completeness you should do this
message.saveChanges();
// transport = session.getTransport("smtp");Transport transport = null;
transport = session.getTransport(to);
<snip>transport.connect(smtpServer, userId, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}
Regards,
Gary