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 = ""

// Set up the mail object
val properties = System.getProperties
properties.put("", 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")

// And send it


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