Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/328.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
scala-javax.mail.AuthenticationFailedException_Java_Scala_Jakarta Mail - Fatal编程技术网

scala-javax.mail.AuthenticationFailedException

scala-javax.mail.AuthenticationFailedException,java,scala,jakarta-mail,Java,Scala,Jakarta Mail,我的目标是通过电子邮件发送数据帧。下面是我的一段代码: 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").se

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

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)
  }
}
但是当我执行代码时,我得到以下错误:

线程“main”javax.mail.AuthenticationFailedException中出现异常


这里缺少什么。

去掉验证器(根本没有使用)和
mail.smtp.user
mail.smtp.password
mail.smtp.auth
属性,然后调用。如果仍然不起作用,请发布。

除去验证器(根本没有使用)和
mail.smtp.user
mail.smtp.password
mail.smtp.auth
属性,然后调用。如果仍然不起作用,请发布。

我需要向会话传递身份验证,这是我错过的,下面的代码为我工作:

val sparkConf = new SparkConf().setAppName("E-mail Alert").setMaster("local")
val sc = new SparkContext(sparkConf)
var bodyText = "Test mail"
val username = "*****************"
val password = "************************"
val smtpHost = "email-smtp.us-east-1.amazonaws.com"

// Set up the mail object
val properties = System.getProperties
properties.put("mail.smtp.host", smtpHost)
properties.put("mail.smtp.user", username);
properties.put("mail.smtp.password", password);
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.port", "587")
properties.put("mail.smtp.starttls.enable", "true");

val auth:Authenticator = new Authenticator() {
  override def getPasswordAuthentication = new
      PasswordAuthentication(username, password)
}

val session = Session.getInstance(properties,auth)
val message = new MimeMessage(session)

// 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)

我需要向会话传递身份验证,这是我错过的,下面的代码为我工作:

val sparkConf = new SparkConf().setAppName("E-mail Alert").setMaster("local")
val sc = new SparkContext(sparkConf)
var bodyText = "Test mail"
val username = "*****************"
val password = "************************"
val smtpHost = "email-smtp.us-east-1.amazonaws.com"

// Set up the mail object
val properties = System.getProperties
properties.put("mail.smtp.host", smtpHost)
properties.put("mail.smtp.user", username);
properties.put("mail.smtp.password", password);
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.port", "587")
properties.put("mail.smtp.starttls.enable", "true");

val auth:Authenticator = new Authenticator() {
  override def getPasswordAuthentication = new
      PasswordAuthentication(username, password)
}

val session = Session.getInstance(properties,auth)
val message = new MimeMessage(session)

// 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)

你为什么说它们根本没有被使用,如果是的话,我能让它们使用什么呢?据我所知(我不是Scala专家),你声明的验证器从未被使用过。通常它会被传递给Session.getInstance方法。不管怎样,照我说的做。你为什么说它们根本没有被使用,如果是的话,我能让它们使用什么呢?据我所知(我不是Scala专家),你声明的验证器从未被使用过。通常它会被传递给Session.getInstance方法。不管怎样,照我说的做。