gpt4 book ai didi

java - scala - javax.mail.AuthenticationFailedException

转载 作者:行者123 更新时间:2023-12-02 03:09:46 26 4
gpt4 key购买 nike

我的目标是通过电子邮件发送数据帧。下面是我的一段代码:

import javax.mail._
import javax.mail.internet._
import org.apache.spark.{SparkConf, SparkContext}

object EmailAlert {
def main(args: Array[String]): Unit = {

val sparkConf = new SparkConf().setAppName("E-mail Alert").setMaster("local")
val sc = new SparkContext(sparkConf)
var bodyText = "Test mail"

// Set up the mail object
val properties = System.getProperties
properties.put("mail.smtp.host", "email-smtp.us-east-1.amazonaws.com")
properties.put("mail.smtp.user", "********");
properties.put("mail.smtp.password", "********");
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.port", "587")
properties.put("mail.smtp.starttls.enable", "true");
val session = Session.getInstance(properties)
val message = new MimeMessage(session)

def getPasswordAuthentication(username:String, password:String):Authenticator=
{
new Authenticator(){
override def getPasswordAuthentication():PasswordAuthentication = {
new PasswordAuthentication(username, password);
}}
}

// Set the from, to, subject, body text
message.setFrom(new InternetAddress("no-reply@****.com"))
message.setRecipients(Message.RecipientType.TO, "ajayv@****.com")
message.setSubject("Count of DeviceIDs we are sent daily")
message.setText(bodyText)

// And send it
Transport.send(message)
}
}

但是当我执行代码时出现以下错误:

Exception in thread "main" javax.mail.AuthenticationFailedException

我在这里缺少什么。

最佳答案

删除身份 validator (根本没有使用)和 mail.smtp.usermail.smtp.password mail.smtp.auth 属性,然后调用Transport.send method that takes a user name and password 。如果还是不行,发帖JavaMail debug output .

关于java - scala - javax.mail.AuthenticationFailedException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41237519/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com