Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ServiceConfigurationError IMAPProvider not a subtype #513

Closed
sreyasvpariyath opened this issue Jan 3, 2023 · 2 comments
Closed

ServiceConfigurationError IMAPProvider not a subtype #513

sreyasvpariyath opened this issue Jan 3, 2023 · 2 comments

Comments

@sreyasvpariyath
Copy link

Hi, I have been trying to integrate greenmail to test my email sending code, I am getting the following error when I run the test, Could you please help with it.

Exception in thread "smtp:127.0.0.1:3025<-/127.0.0.1:55914" java.util.ServiceConfigurationError: javax.mail.Provider: com.sun.mail.imap.IMAPProvider not a subtype
	at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:593)
	at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1244)
	at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1273)
	at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1309)
	at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1393)
	at javax.mail.Session.loadProviders(Session.java:964)
	at javax.mail.Session.<init>(Session.java:254)
	at javax.mail.Session.getDefaultInstance(Session.java:355)
	at javax.mail.Session.getDefaultInstance(Session.java:395)
	at com.icegreen.greenmail.util.GreenMailUtil.newMimeMessage(GreenMailUtil.java:69)
	at com.icegreen.greenmail.smtp.commands.DataCommand.execute(DataCommand.java:54)
	at com.icegreen.greenmail.smtp.SmtpHandler.handleCommand(SmtpHandler.java:92)
	at com.icegreen.greenmail.smtp.SmtpHandler.run(SmtpHandler.java:46)
	at com.icegreen.greenmail.server.AbstractServer.lambda$handleClientSocket$0(AbstractServer.java:165)
	at java.base/java.lang.Thread.run(Thread.java:833)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class JavaMailSenderIT {

  @RegisterExtension
  static GreenMailExtension greenMail = new GreenMailExtension(ServerSetupTest.SMTP)
    .withConfiguration(GreenMailConfiguration.aConfig().withUser("duke", "springboot"))
    .withPerMethodLifecycle(false);

  @Autowired
  private JavaMailSender javaMailSender;

  @Test
  void shouldUseGreenMail() {

    SimpleMailMessage mail = new SimpleMailMessage();
    mail.setFrom("[email protected]");
    mail.setSubject("A new message for you");
    mail.setText("Hello GreenMail!");
    mail.setTo("[email protected]");

    javaMailSender.send(mail);

    // awaitility
    await().atMost(2, SECONDS).untilAsserted(() -> {
      MimeMessage[] receivedMessages = greenMail.getReceivedMessages();
      assertEquals(1, receivedMessages.length);

      MimeMessage receivedMessage = receivedMessages[0];
      assertEquals("Hello GreenMail!", GreenMailUtil.getBody(receivedMessage));
      assertEquals(1, receivedMessage.getAllRecipients().length);
      assertEquals("[email protected]", receivedMessage.getAllRecipients()[0].toString());
    });
  }
@marcelmay
Copy link
Member

Hi @sreyasvpariyath ,

which Spring Boot version do you use?

@sreyasvpariyath
Copy link
Author

sreyasvpariyath commented Jan 4, 2023

Hi @marcelmay
Thanks it seems working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants