Search code examples
javajakarta-mail

Gradle Java Mailing Bot Dosent Work Because Of finished With Non-Zero Exit Code 1


So I Made A Java Mailing Bot Using javax.mail(Gradle)

After Hours Of Debugging I Got The Dependency To Work

But I Get This Error Now

I Am Using JDK 11

IntelliJ Idea Ultimate 2020.2.3

> Process 'command 'C:/Program Files/Java/jdk-11.0.8/bin/java.exe'' finished with non-zero exit value 1

This Does Not Allow Me To Run Main.Main()

Here Is The Code - build.gradle

    id 'java'
}

group 'com.putopug.mailerdeamon'
version 'DAEMON'

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    //compile group: 'javax.mail', name: 'javax.mail-api', version: '1.6.2'
    //compile 'javax.mail:javax.mail-api:1.6.2'
    compile group: 'javax.mail', name: 'mail', version: '1.5.0-b01'
}

Main.java


import javax.mail.*;
import javax.mail.internet.*;
import java.io.Console;
import java.util.Properties;

public class Main {
    public static void main(String[] args) throws MessagingException {
        Properties prop = new Properties();
        prop.put("mail.smtp.auth", true);
        prop.put("mail.smtp.starttls.enable", "true");
        prop.put("mail.smtp.host", "smtp.gmail.com");
        prop.put("mail.smtp.port", "465");
        prop.put("mail.smtp.ssl.trust", "smtp.gmail.com");

        Session session = Session.getInstance(prop, new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("gemail", "ddddddd");
            }
        });


        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress("email"));
        message.setRecipients(
                Message.RecipientType.TO, InternetAddress.parse("email"));
        message.setSubject("Mail Subject");

        String msg = "This is my first email using JavaMailer";

        MimeBodyPart mimeBodyPart = new MimeBodyPart();
        mimeBodyPart.setContent(msg, "text/html");

        Multipart multipart = new MimeMultipart();
        multipart.addBodyPart(mimeBodyPart);

        message.setContent(multipart);

        Transport.send(message);

    }
}

Solution

  • I Just Had To Surround The Code With A Try Catch loop