mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-09 06:55:54 +01:00
Add support to MIME Text part.
This commit is contained in:
@@ -19,8 +19,12 @@ import SystemSettingsService.Smtp
|
|||||||
* Please see the plugin for details.
|
* Please see the plugin for details.
|
||||||
*/
|
*/
|
||||||
trait Notifier {
|
trait Notifier {
|
||||||
|
def toNotify(subject: String, htmlMsg: String)
|
||||||
|
(recipients: Account => Session => Seq[String])(implicit context: Context): Unit = {
|
||||||
|
toNotify(subject, htmlMsg, None)(recipients)
|
||||||
|
}
|
||||||
|
|
||||||
def toNotify(subject: String, msg: String)
|
def toNotify(subject: String, htmlMsg: String, textMsg: Option[String])
|
||||||
(recipients: Account => Session => Seq[String])(implicit context: Context): Unit
|
(recipients: Account => Session => Seq[String])(implicit context: Context): Unit
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -35,7 +39,7 @@ object Notifier {
|
|||||||
class Mailer(private val smtp: Smtp) extends Notifier {
|
class Mailer(private val smtp: Smtp) extends Notifier {
|
||||||
private val logger = LoggerFactory.getLogger(classOf[Mailer])
|
private val logger = LoggerFactory.getLogger(classOf[Mailer])
|
||||||
|
|
||||||
def toNotify(subject: String, msg: String)
|
def toNotify(subject: String, htmlMsg: String, textMsg: Option[String] = None)
|
||||||
(recipients: Account => Session => Seq[String])(implicit context: Context): Unit = {
|
(recipients: Account => Session => Seq[String])(implicit context: Context): Unit = {
|
||||||
context.loginAccount.foreach { loginAccount =>
|
context.loginAccount.foreach { loginAccount =>
|
||||||
val database = Database()
|
val database = Database()
|
||||||
@@ -43,7 +47,7 @@ class Mailer(private val smtp: Smtp) extends Notifier {
|
|||||||
val f = Future {
|
val f = Future {
|
||||||
database withSession { session =>
|
database withSession { session =>
|
||||||
recipients(loginAccount)(session) foreach { to =>
|
recipients(loginAccount)(session) foreach { to =>
|
||||||
send(to, subject, msg, loginAccount)
|
send(to, subject, htmlMsg, loginAccount, textMsg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"Notifications Successful."
|
"Notifications Successful."
|
||||||
@@ -55,7 +59,7 @@ class Mailer(private val smtp: Smtp) extends Notifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def send(to: String, subject: String, msg: String, loginAccount: Account): Unit = {
|
def send(to: String, subject: String, htmlMsg: String, loginAccount: Account, textMsg: Option[String] = None): Unit = {
|
||||||
val email = new HtmlEmail
|
val email = new HtmlEmail
|
||||||
email.setHostName(smtp.host)
|
email.setHostName(smtp.host)
|
||||||
email.setSmtpPort(smtp.port.get)
|
email.setSmtpPort(smtp.port.get)
|
||||||
@@ -80,13 +84,16 @@ class Mailer(private val smtp: Smtp) extends Notifier {
|
|||||||
}
|
}
|
||||||
email.setCharset("UTF-8")
|
email.setCharset("UTF-8")
|
||||||
email.setSubject(subject)
|
email.setSubject(subject)
|
||||||
email.setHtmlMsg(msg)
|
email.setHtmlMsg(htmlMsg)
|
||||||
|
textMsg.foreach{ msg =>
|
||||||
|
email.setTextMsg(msg)
|
||||||
|
}
|
||||||
|
|
||||||
email.addTo(to).send
|
email.addTo(to).send
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
class MockMailer extends Notifier {
|
class MockMailer extends Notifier {
|
||||||
def toNotify(subject: String, msg: String)
|
def toNotify(subject: String, htmlMsg: String, textMsg: Option[String] = None)
|
||||||
(recipients: Account => Session => Seq[String])(implicit context: Context): Unit = ()
|
(recipients: Account => Session => Seq[String])(implicit context: Context): Unit = ()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user