Hi all,
I'm trying to send a simple email via an imap mail server but when I try to get the Transport for imap I get the following:
javax.mail.NoSuchProviderException: invalid provider
at javax.mail.Session.getTransport(Session.java:714)
My code is below:
public static void main(String[] args) {
Properties props = System.getProperties();
props.put("mail.imap.host", "~REMOVED FOR PRIVACY REASONS~");
Session session = Session.getDefaultInstance(props, null);
try{
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("XXXXXXXXX@XXXXXX.ie"));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("XXXXXXXX@XXXXXXXX.ie", false));
msg.setSubject("Test Java Message");
msg.setText("This is a sample email");
msg.setHeader("X-Mailer", "O'Reily SimpleSender");
Transport t = session.getTransport("imap");
t.send(msg);
}
catch(AddressException ae){
ae.printStackTrace();
}
catch(MessagingException me){
me.printStackTrace();
}
}
The code always fails at the transport line
Transport t = session.getTransport("imap");
Even though when I debug it I can see the imap provider in the providers Vector of the session.
I'm only beginning so it might be something obvious but any help would be appreciated.
Cheers,
Illu