0
私はスパークデータフレームでテーブルデータを取得してメールで送信する必要があるこのプロジェクトに取り組んでいます。使用する言語はScalaです。メールでSpark DataFrameを送信する
次のようにテーブルデータが保持するデータフレームは、: -
val sqlDfUT = hiveCon.sql("select * from UserTable")
私は、メールのメッセージ本文として「sqlDfUT」を送信する必要があります。
メールを送信するためのコードは次のとおりです。
sendScalaMail("[email protected]","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) && (mailIdList.equals(""))){
writeToLog("Email ID not defined")
}
writeToLog("<----Sender---->"+mailSender)
writeToLog("<----strMailBody---->"+strMailBody)
writeToLog("<----mailIdList---->"+mailIdList)
writeToLog("<----strMailSubj---->"+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 <- 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 <- 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 =>{
me.printStackTrace()
writeToLog("<---Error in method sendScalaMail--->"+me)
}
} }
しかし、私は
msg.setRecipients(Message.RecipientType.TO, address)
行でエラーを取得していますし、エラーメッセージは、私はなります
overloaded method value setRecipients with alternatives: (x$1: javax.mail.Message.RecipientType,x$2: String)Unit <and> (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])
です私が指導を得ることができたら本当にうれしい。ありがとうございます
エラーはSparkに接続されていませんが、Mailing APIで接続されています。ちょうど1つの長い、完全ではないDataFrame –
質問を更新したい、私は完全なテーブルのデータを(レコードが少ないですが)メールで送信したいと思います。 –
'address'の型が正しくない場合、' Array [Address] ' –