[英]Im using javax mail , it gives this error. java.lang.NoClassDefFoundError: javax/mail/internet/AddressException
i have added the main.jar library after downloading it from the official oracle website.从官方 oracle 网站下载后,我添加了 main.jar 库。 my code shows no syntax errors.
我的代码没有显示语法错误。 i keep getting this error: java.lang.NoClassDefFoundError: javax/mail/internet/AddressException any ideas on what to do?
我不断收到此错误: java.lang.NoClassDefFoundError: javax/mail/internet/AddressException 有什么想法吗?
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class EmailSender {
public static void SendMail(String recepient) throws Exception {
System.out.println("prepaering to send email ya bro");
Properties properties = new Properties();
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.starttls.enable", "true");
properties.put("mail.smtp.host", "smtp.gmail.com");
properties.put("mail.smtp.auth", "587");
String myAccountEmail = "xxxxxxxx@gmail.com";
String password = "xxxxxxxxxxxx";
Session session = Session.getInstance(properties, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(myAccountEmail, password);
}
});
Message message = prepareMessage(session, myAccountEmail, recepient);
Transport.send(message);
System.out.println("meshe lhal maalim");
}
private static Message prepareMessage(Session session, String myAccountEmail, String recepient) {
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(myAccountEmail));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(recepient));
message.setSubject("SHUUUUUUU");
message.setText("ENSAAA");
return message;
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
}
return null;
}
}
You are probably lacking the implementation JAR for the JavaMail API.您可能缺少 JavaMail API 的实现 JAR。 Here are the appropriate lines from a Maven POM:
以下是 Maven POM 中的相应行:
<dependency>
<groupId>javax.mail</groupId>
<artifactId>javax.mail-api</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
</dependency>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.