Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Invalid provider for imap question

843834Jan 4 2008 — edited Jan 4 2008
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 1 2008
Added on Jan 4 2008
1 comment
618 views