我的目标是通过电子邮件发送数据帧。下面是我的代码:
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="dash-menu">
<h2>Hi , Welcome back</h2>
<div class="dash-header">
<ul>
<li>Menu1</li>
<li>Menu2</li>
<li>Menu3</li>
<li><i class="fa fa-bars" aria-hidden="true"></i></li>
</ul>
<img src="">
</div><!--dash-header-->
</div><!--dash-menu-->
但是当我执行代码时,我得到以下错误:
线程中的异常&#34; main&#34; javax.mail.AuthenticationFailedException
我在这里缺少什么。
答案 0 :(得分:1)
摆脱身份验证器(根本没有使用)和mail.smtp.user
,mail.smtp.password
和mail.smtp.auth
属性,然后调用Transport.send method that takes a user name and password 。如果仍然无效,请发布JavaMail debug output。
答案 1 :(得分:1)
我需要将身份验证传递给会话,这是我错过的,下面的代码对我有用:
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)