score:1

Accepted answer

I need to pass Authentication to the session which is what i am missed, Below code worked for me :

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)

score:1

Get rid of the Authenticator (which isn't being used at all) and the mail.smtp.user, mail.smtp.password, and mail.smtp.auth properties, then call the Transport.send method that takes a user name and password. If it still doesn't work, post the JavaMail debug output.


Related Query

More Query from same tag