simple-java-mail: Class not being able to be found when using Java 10

I tried sending an email and when I tried to run the code it threw a ClassNotFoundExpection. I have everything imported via Maven my pom.xml which looks like the following:

    <groupId>me.willis.myplugin</groupId>
    <artifactId>MyPlugin</artifactId>
    <version>1.0-SNAPSHOT</version>

    <repositories>
        <repository>
            <id>spigot-repo</id>
            <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
        </repository>
    </repositories>


    <dependencies>
        <!--Spigot API-->
        <dependency>
            <groupId>org.spigotmc</groupId>
            <artifactId>spigot-api</artifactId>
            <version>1.12.2-R0.1-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>
        <!--Bukkit API-->
        <dependency>
            <groupId>org.bukkit</groupId>
            <artifactId>bukkit</artifactId>
            <version>1.12.2-R0.1-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.simplejavamail</groupId>
            <artifactId>simple-java-mail</artifactId>
            <version>5.0.3</version>
        </dependency>
        <!--Google Authentication-->
        <dependency>
            <groupId>com.warrenstrange</groupId>
            <artifactId>googleauth</artifactId>
            <version>1.1.2</version>
        </dependency>
    </dependencies>

</project>

The error that showed up was the following: java.lang.NoClassDefFoundError: org/simplejavamail/email/EmailBuilder

The code I was using:

        Email email = EmailBuilder.startingBlank()
                .to("RandomEmail@gmail.com")
                .withSubject("test")
                .withPlainText("hello")
                .buildEmail();

        Mailer mailer = MailerBuilder
                .withSMTPServer("smtp.gmail.com", 587, "MyEmail@gmail.com", "MyPassword")
                .withTransportStrategy(TransportStrategy.SMTP_TLS)
                .withSessionTimeout(10 * 1000)
                .clearEmailAddressCriteria()
                .withDebugLogging(true)
                .buildMailer();

        mailer.sendMail(email);
    }

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (10 by maintainers)

Commits related to this issue

Most upvoted comments

@Willim7 , @ethfun, any update from your side?

org.simplejavamail.mailer.MailerException: Email is not valid: missing sender

The code I am using is the same as the code stated in my first post, just wondering what I am doing wrong, thank you!

This is easier to explain at least. You have not provided a From address. This is necessary for the server to bounce mails back to, to identify you in case of an authenticated SMTP server and more to the point, to identify yourself to the receiver (you can’t anonymously send an email as such).

Also see:

The fix is easy enough:

Email email = EmailBuilder.startingBlank()
                .from("m.baker@mbakery.com") // or:
                .from("Michel Baker", "m.baker@mbakery.com")
                (..)
                .buildEmail();

Hey, I switched everything to Java 8 and every class seems to be able to be found, weird must be something with Java 10 that might be a bug when it comes to compiling/shading classes with Maven. However I did end up getting an error which is:

org.simplejavamail.mailer.MailerException: Email is not valid: missing sender

The code I am using is the same as the code stated in my first post, just wondering what I am doing wrong, thank you!