所以我用javax.mail(gradle)制作了一个java邮件机器人
经过几个小时的调试,我得到了依赖性的工作
但我现在犯了这个错误
我正在使用JDK11
intellij idea终极版2020.2.3
> Process 'command 'C:/Program Files/Java/jdk-11.0.8/bin/java.exe'' finished with non-zero exit value 1
这不允许我运行main.main()
这是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'
}
主.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);
}
}
1条答案
按热度按时间kq0g1dla1#
我只需要用try-catch循环来包围代码