Error in sending email using commons-email-1.3(使用 commons-email-1.3 发送电子邮件时出错)
问题描述
发送电子邮件时,我使用 commons-email-1.3 收到以下错误.
我已经下载并添加了外部 jar 到项目中.
请帮我解决这个问题!
While sending email I am getting the following errors using commons-email-1.3.
I have downloaded and added external jar's to the project.
Please help me fix this problem!
package mypkg;
import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.SimpleEmail;
public class sendingmail {
public static void main(String[] args) throws Exception {
Email email = new SimpleEmail();
email.setSmtpPort(587);
email.setAuthenticator(new DefaultAuthenticator("myid","mypwd")); //Here is the error
email.setDebug(false);
email.setHostName("smtp.gmail.com");
email.setFrom("me@gmail.com");
email.setSubject("Hi");
email.setMsg("This is a test mail ... :-)");
email.addTo("you@gmail.com");
email.setTLS(true);
email.send();
System.out.println("Mail sent!");
}
}
给出错误的行是
email.setAuthenticator(new DefaultAuthenticator("myid","mypwd"));
错误信息是
线程main"java.lang.Error 中的异常:未解决的编译问题:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
无法解析类型 javax.mail.Authenticator.它是从所需的 .class 文件中间接引用的
来自类型 Email 的方法 setAuthenticator(Authenticator) 指的是 mypkg.mailtest.main(mailtest.java:13) 处缺少的类型 Authenticator
The type javax.mail.Authenticator cannot be resolved. It is indirectly referenced from required .class files
The method setAuthenticator(Authenticator) from the type Email refers to the missing type Authenticator at mypkg.mailtest.main(mailtest.java:13)
推荐答案
请从指定链接下载jar
Please download the jars from the specified links
激活JAR
Java Mail jar
这篇关于使用 commons-email-1.3 发送电子邮件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 commons-email-1.3 发送电子邮件时出错


- Java包名称中单词分隔符的约定是什么? 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01