This is an automated email from the ASF dual-hosted git repository.

kirs pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-seatunnel.git


The following commit(s) were added to refs/heads/dev by this push:
     new cdde367e [Improve][Connectors] enhancement spark-email-sink (#1692)
cdde367e is described below

commit cdde367edd200f770099577fe3b5642e6c4542b2
Author: lvshaokang <[email protected]>
AuthorDate: Wed Apr 13 23:26:05 2022 +0800

    [Improve][Connectors] enhancement spark-email-sink (#1692)
    
    * enable set ssl/tls option
    
    * support ArrayType data
---
 docs/en/connector/sink/Email.md                    | 51 +++++++++++++---------
 .../seatunnel/spark/email/sink/DataLocator.scala   |  2 +
 .../apache/seatunnel/spark/email/sink/Email.scala  | 13 ++++--
 3 files changed, 42 insertions(+), 24 deletions(-)

diff --git a/docs/en/connector/sink/Email.md b/docs/en/connector/sink/Email.md
index bfb69a31..8f50db9c 100644
--- a/docs/en/connector/sink/Email.md
+++ b/docs/en/connector/sink/Email.md
@@ -15,19 +15,21 @@ Engine Supported and plugin name
 
 ## Options
 
-| name     | type   | required | default value |
-| -------- | ------ | -------- | ------------- |
-| subject  | string | yes      | -             |
-| from     | string | yes      | -             |
-| to       | string | yes      | -             |
-| bodyText | string | no       | -             |
-| bodyHtml | string | no       | -             |
-| cc       | string | no       | -             |
-| bcc      | string | no       | -             |
-| host     | string | yes      | -             |
-| port     | string | yes      | -             |
-| password | string | yes      | -             |
-| limit    | string | no       | 100000        |
+| name     | type    | required | default value |
+|----------|---------|----------|---------------|
+| subject  | string  | yes      | -             |
+| from     | string  | yes      | -             |
+| to       | string  | yes      | -             |
+| bodyText | string  | no       | -             |
+| bodyHtml | string  | no       | -             |
+| cc       | string  | no       | -             |
+| bcc      | string  | no       | -             |
+| host     | string  | yes      | -             |
+| port     | string  | yes      | -             |
+| password | string  | yes      | -             |
+| limit    | string  | no       | 100000        |
+| use_ssl  | boolean | no       | false         |
+| use_tls  | boolean | no       | false         |
 
 ### subject [string]
 
@@ -73,18 +75,27 @@ The password of the email sender, the user name is the 
sender specified by `from
 
 The number of rows to include, the default is `100000`
 
+### use_ssl [boolean]
+
+The security properties for encrypted link to smtp server, the default is 
`false`
+
+### use_tls [boolean]
+
+The security properties for encrypted link to smtp server, the default is 
`false`
+
 ## Examples
 
 ```bash
 Email {
-       subject = "Report statistics",
-       from = "[email protected]",
-       to = "[email protected],[email protected]",
+    subject = "Report statistics",
+    from = "[email protected]",
+    to = "[email protected],[email protected]",
     cc = "[email protected],[email protected]",
     bcc = "[email protected],[email protected]",
-       host= "stmp.exmail.qq.com",
-       port= "25",
-       password = "***********",
-    limit = "1000"
+    host= "stmp.exmail.qq.com",
+    port= "25",
+    password = "***********",
+    limit = "1000",
+    use_ssl = true
 }
 ```
diff --git 
a/seatunnel-connectors/seatunnel-connectors-spark/seatunnel-connector-spark-email/src/main/scala/org/apache/seatunnel/spark/email/sink/DataLocator.scala
 
b/seatunnel-connectors/seatunnel-connectors-spark/seatunnel-connector-spark-email/src/main/scala/org/apache/seatunnel/spark/email/sink/DataLocator.scala
index 0d4bfc9b..fda1a722 100644
--- 
a/seatunnel-connectors/seatunnel-connectors-spark/seatunnel-connector-spark-email/src/main/scala/org/apache/seatunnel/spark/email/sink/DataLocator.scala
+++ 
b/seatunnel-connectors/seatunnel-connectors-spark/seatunnel-connector-spark-email/src/main/scala/org/apache/seatunnel/spark/email/sink/DataLocator.scala
@@ -26,6 +26,7 @@ import org.apache.poi.ss.util.{AreaReference, CellReference}
 import org.apache.poi.xssf.usermodel.{XSSFTable, XSSFWorkbook}
 import Utils.MapIncluding
 
+import scala.collection.mutable
 import scala.util.matching.Regex
 
 trait DataLocator {
@@ -138,6 +139,7 @@ trait AreaDataLocator extends DataLocator {
       case l: Long => WriteCell(l)
       case b: BigDecimal => WriteCell(b)
       case b: java.math.BigDecimal => WriteCell(BigDecimal(b))
+      case arr: mutable.WrappedArray.ofRef[_] => WriteCell(arr.mkString(","))
       case null => WriteCell.Empty
     }
 }
diff --git 
a/seatunnel-connectors/seatunnel-connectors-spark/seatunnel-connector-spark-email/src/main/scala/org/apache/seatunnel/spark/email/sink/Email.scala
 
b/seatunnel-connectors/seatunnel-connectors-spark/seatunnel-connector-spark-email/src/main/scala/org/apache/seatunnel/spark/email/sink/Email.scala
index 6c31647b..69ac5e35 100644
--- 
a/seatunnel-connectors/seatunnel-connectors-spark/seatunnel-connector-spark-email/src/main/scala/org/apache/seatunnel/spark/email/sink/Email.scala
+++ 
b/seatunnel-connectors/seatunnel-connectors-spark/seatunnel-connector-spark-email/src/main/scala/org/apache/seatunnel/spark/email/sink/Email.scala
@@ -89,8 +89,10 @@ class Email extends SparkBatchSink {
     val host = config.getString("host")
     val port = config.getInt("port")
     val password = config.getString("password")
+    val ssl = if (config.hasPath("use_ssl")) config.getBoolean("use_ssl") else 
false
+    val tls = if (config.hasPath("use_tls")) config.getBoolean("use_tls") else 
false
 
-    val mailer: SMTPMailer = createMailer(host, port, from, password)
+    val mailer: SMTPMailer = createMailer(host, port, from, password, ssl, tls)
     val result: String = mailer.send(email)
   }
 
@@ -103,14 +105,17 @@ class Email extends SparkBatchSink {
       port: Int,
       user: String,
       password: String,
+      ssl: Boolean = false,
+      tls: Boolean = false,
       timeout: Int = 10000,
-      connectionTimeout: Int = 10000): SMTPMailer = {
+      connectionTimeout: Int = 10000
+      ): SMTPMailer = {
     // STMP's service SMTPConfiguration
     val configuration = new SMTPConfiguration(
       host,
       port,
-      false,
-      false,
+      ssl,
+      tls,
       false,
       Option(user),
       Option(password),

Reply via email to