byzer-lang
byzer-lang copied to clipboard
Send email error when set `properties.mail.smtp.starttls.enable`= "true".
Problem
I use Byzer to send mail according to this document.
I'd like to send email with config "mail.smtp.starttls.enable=true", so I add configuration properties.mail.smtp.starttls.enable
= "true" to sendEmail ET.
Here is my script:
set EMAIL_TITLE = "这是邮件标题";
set EMAIL_BODY = '''什么东西''';
set EMAIL_TO = "[email protected]";
set HOST = "smtp.office365.com";
-- 使用配置账号的方式
run command as SendMessage.``
where method = "mail"
and mailType = "config"
and from = "[email protected]"
and to = "${EMAIL_TO}"
and subject = "${EMAIL_TITLE}"
and content = "${EMAIL_BODY}"
-- 设置邮件客户端使用的服务器域名、端口号
and smtpHost = "${HOST}"
and smtpPort = "587"
-- 设置邮件客户端的协议TLS,如果使用SSL协议,请配置:`properties.mail.smtp.ssl.enable`= "true"
and attachmentContentType="text/csv"
and attachmentPaths = "/tmp/jira/jira-issue-worklog.csv"
and `properties.mail.smtp.starttls.enable`= "true"
-- and `properties.mail.debug`="true"
-- and `properties.mail.smtp.ssl.trust`="${HOST}"
and `properties.mail.smtp.ssl.protocols`="TLSv1.2"
-- 设置邮件客户端的用户名、授权码
and userName = "[email protected]"
and password="password"
;
Error happend when I send the email. Here is the Exception:
Could not connect to SMTP host: smtp.office365.com, port: 587
javax.mail.MessagingException: Could not connect to SMTP host: smtp.office365.com, port: 587;
nested exception is:
javax.net.ssl.SSLException: Unsupported or unrecognized SSL message
com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2211)
com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:740)
javax.mail.Service.connect(Service.java:388)
javax.mail.Service.connect(Service.java:246)
javax.mail.Service.connect(Service.java:195)
javax.mail.Transport.send0(Transport.java:254)
javax.mail.Transport.send(Transport.java:124)
streaming.dsl.mmlib.algs.MailAgent.sendMessage(SQLSendMessage.scala:592)
streaming.dsl.mmlib.algs.SQLSendMessage.train(SQLSendMessage.scala:414)
tech.mlsql.dsl.adaptor.TrainAdaptor.parse(TrainAdaptor.scala:116)
streaming.dsl.ScriptSQLExecListener.execute$1(ScriptSQLExec.scala:408)
streaming.dsl.ScriptSQLExecListener.exitSql(ScriptSQLExec.scala:447)
streaming.dsl.parser.DSLSQLParser$SqlContext.exitRule(DSLSQLParser.java:296)
org.antlr.v4.runtime.tree.ParseTreeWalker.exitRule(ParseTreeWalker.java:47)
org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:30)
org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:28)
streaming.dsl.ScriptSQLExec$._parse(ScriptSQLExec.scala:160)
streaming.dsl.ScriptSQLExec$.parse(ScriptSQLExec.scala:147)
streaming.rest.RestController.$anonfun$script$1(RestController.scala:153)
tech.mlsql.job.JobManager$.run(JobManager.scala:74)
tech.mlsql.job.JobManager$$anon$1.run(JobManager.scala:91)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)
caused by:
javax.net.ssl.SSLException: Unsupported or unrecognized SSL message
sun.security.ssl.SSLSocketInputRecord.handleUnknownRecord(SSLSocketInputRecord.java:448)
sun.security.ssl.SSLSocketInputRecord.decode(SSLSocketInputRecord.java:184)
sun.security.ssl.SSLTransport.decode(SSLTransport.java:109)
sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1383)
sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1291)
sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:435)
com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:626)
com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:400)
com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:217)
com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2175)
com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:740)
javax.mail.Service.connect(Service.java:388)
javax.mail.Service.connect(Service.java:246)
javax.mail.Service.connect(Service.java:195)
javax.mail.Transport.send0(Transport.java:254)
javax.mail.Transport.send(Transport.java:124)
streaming.dsl.mmlib.algs.MailAgent.sendMessage(SQLSendMessage.scala:592)
streaming.dsl.mmlib.algs.SQLSendMessage.train(SQLSendMessage.scala:414)
tech.mlsql.dsl.adaptor.TrainAdaptor.parse(TrainAdaptor.scala:116)
streaming.dsl.ScriptSQLExecListener.execute$1(ScriptSQLExec.scala:408)
streaming.dsl.ScriptSQLExecListener.exitSql(ScriptSQLExec.scala:447)
streaming.dsl.parser.DSLSQLParser$SqlContext.exitRule(DSLSQLParser.java:296)
org.antlr.v4.runtime.tree.ParseTreeWalker.exitRule(ParseTreeWalker.java:47)
org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:30)
org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:28)
streaming.dsl.ScriptSQLExec$._parse(ScriptSQLExec.scala:160)
streaming.dsl.ScriptSQLExec$.parse(ScriptSQLExec.scala:147)
streaming.rest.RestController.$anonfun$script$1(RestController.scala:153)
tech.mlsql.job.JobManager$.run(JobManager.scala:74)
tech.mlsql.job.JobManager$$anon$1.run(JobManager.scala:91)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)
Root Cause & Solution
It seems like it happened because the SSL
encryption protocol inconsistent with the configuration was used, which specified to use the STARTTLS
. So I debug the code and found some bugs here:
Before this code, there is such a processing:
params.filter(_._1.startsWith("properties.")).foreach { case (k, v) =>
properties.setProperty(k.stripPrefix("properties."), v)
}
So I fix it.