title: Sending a Spark DataFrame via Email
body: <p>I am working on this project where I need to get the table data in a spark dataframe and send it in a mail. The language to be used is Scala.</p>
  
  <p>The dataframe to hold the table data is as follows:-</p>
  
  <pre><code>val sqlDfUT = hiveCon.sql("select * from UserTable")
  </code></pre>
  
  <p>I need to send "sqlDfUT" as a message body in a mail.</p>
  
  <p>The code for sending the mail is:</p>
  
  <pre><code>sendScalaMail("monitor@foo.com","Users Data Sent : \n " + sqlDfUT +
                      ",\nMail sent from host: " + java.net.InetAddress.getLocalHost().getHostName(),
                      "12525","Hive Data Checking completed for given User: 12525" )
  
  def sendScalaMail (mailSender:String, strMailBody:String, mailIdList:String, strMailSubj:String)={
  
  if ((mailIdList == null) &amp;&amp; (mailIdList.equals(""))){
  
    writeToLog("Email ID not defined")
  }
  writeToLog("&lt;----Sender----&gt;"+mailSender)
  writeToLog("&lt;----strMailBody----&gt;"+strMailBody)
  writeToLog("&lt;----mailIdList----&gt;"+mailIdList)
  writeToLog("&lt;----strMailSubj----&gt;"+strMailSubj)
  
  val smtpHost:String = "mail.foo.com"
  val prop:Properties = new Properties()
  prop.put("mail.smtp.host", smtpHost)
  prop.put("mail.debug", "false")
  var session:Session = Session.getInstance(prop)
  var toPersonList:Array[String] = mailIdList.split(",")
  
  var toMailListSB:StringBuffer = new StringBuffer()
  var toPersonName:String = ""
  var toMailId:String = ""
  var index:Int = 0
  
  for(index &lt;- 0 to toPersonList.length){
  
    toPersonName = toPersonList(index).asInstanceOf[String]
    toMailId = toPersonName+"@mail.foo.com"
    toMailListSB.append(toMailId)
    toMailListSB.append(";")
  
  }
  try{
    var msg:MimeMessage = new MimeMessage(session)
    msg.setFrom(new InternetAddress(mailSender))
    var toList:Array[String] = toMailListSB.toString().split(",")
    var address:Array[InternetAddress] = new InternetAddress(toList.length.toString()).asInstanceOf[Array[InternetAddress]]
    var i:Int = 0
    for(i &lt;- 0 to toList.length){
      address(i) = new InternetAddress(toList(i))
    }
    msg.setRecipients(Message.RecipientType.TO, address)
    msg.setHeader("Content-Type", "text/html")
    msg.setSubject(strMailSubj)
    msg.setSentDate(new Date())       
    msg.setContent(strMailBody, "text/html")
  
    Transport.send(msg)
  
  }
  catch{
    case me:MessagingException =&gt;{
      me.printStackTrace()
      writeToLog("&lt;---Error in method sendScalaMail---&gt;"+me)
    }
  } }
  </code></pre>
  
  <p>However, I am getting the error in line </p>
  
  <pre><code>msg.setRecipients(Message.RecipientType.TO, address)
  </code></pre>
  
  <p>and the error message is </p>
  
  <pre><code>overloaded method value setRecipients with alternatives: (x$1: javax.mail.Message.RecipientType,x$2: String)Unit &lt;and&gt; (x$1: javax.mail.Message.RecipientType,x$2: Array[javax.mail.Address])Unit cannot be applied to (javax.mail.Message.RecipientType, Array[javax.mail.internet.InternetAddress])
  </code></pre>
  
  <p>I will be really glad if I could get any guidance. Thank you</p>