Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Apache Commons电子邮件库在Java中发送电子邮件时出错_Java_Authentication_Apache Commons Email - Fatal编程技术网

使用Apache Commons电子邮件库在Java中发送电子邮件时出错

使用Apache Commons电子邮件库在Java中发送电子邮件时出错,java,authentication,apache-commons-email,Java,Authentication,Apache Commons Email,我试图使用ApacheCommons库发送电子邮件。但这给了我一个错误的说法 email.setAuthenticator函数中的“setAuthenticator类型(Authenticator)错误” 这是我的密码。我不知道为什么会出现这个错误 public static void sendSimpleMail() throws Exception { Email email = new SimpleEmail(); email.setSmtpPort(587); e

我试图使用ApacheCommons库发送电子邮件。但这给了我一个错误的说法

email.setAuthenticator函数中的“setAuthenticator类型(Authenticator)错误”

这是我的密码。我不知道为什么会出现这个错误

public static void sendSimpleMail() throws Exception {
    Email email = new SimpleEmail();
    email.setSmtpPort(587);
    email.setAuthenticator(new DefaultAuthenticator("me@gmail.com","my gmail password"));
    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!");
}

您可以尝试对直接接收用户名和密码的身份验证数据使用不同的方法,然后将通过commons电子邮件在内部处理身份验证者:

email.setAuthentication("me@gmail.com","my gmail password")

您在
email.setAuthenticator(新的DefaultAuthenticator(“me@gmail.com“,”我的gmail密码“);email.setDebug(false),正确吗?可能与