mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-15 09:55:49 +01:00
change interface to textMsg: String, htmlMsg: Option[String].
SystemSettingsController calls Mailer.send directly. fix it too.
This commit is contained in:
@@ -174,8 +174,9 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
post("/admin/system/sendmail", sendMailForm)(adminOnly { form =>
|
post("/admin/system/sendmail", sendMailForm)(adminOnly { form =>
|
||||||
try {
|
try {
|
||||||
new Mailer(form.smtp).send(form.testAddress,
|
new Mailer(form.smtp).send(form.testAddress,
|
||||||
"Test message from GitBucket", "This is a test message from GitBucket.",
|
"Test message from GitBucket", context.loginAccount.get,
|
||||||
context.loginAccount.get)
|
"This is a test message from GitBucket.", None
|
||||||
|
)
|
||||||
|
|
||||||
"Test mail has been sent to: " + form.testAddress
|
"Test mail has been sent to: " + form.testAddress
|
||||||
|
|
||||||
|
|||||||
@@ -19,12 +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)
|
def toNotify(subject: String, textMsg: String)
|
||||||
(recipients: Account => Session => Seq[String])(implicit context: Context): Unit = {
|
(recipients: Account => Session => Seq[String])(implicit context: Context): Unit = {
|
||||||
toNotify(subject, htmlMsg, None)(recipients)
|
toNotify(subject, textMsg, None)(recipients)
|
||||||
}
|
}
|
||||||
|
|
||||||
def toNotify(subject: String, htmlMsg: String, textMsg: Option[String])
|
def toNotify(subject: String, textMsg: String, htmlMsg: Option[String])
|
||||||
(recipients: Account => Session => Seq[String])(implicit context: Context): Unit
|
(recipients: Account => Session => Seq[String])(implicit context: Context): Unit
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -39,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, htmlMsg: String, textMsg: Option[String] = None)
|
def toNotify(subject: String, textMsg: String, htmlMsg: 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()
|
||||||
@@ -47,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, htmlMsg, loginAccount, textMsg)
|
send(to, subject, loginAccount, textMsg, htmlMsg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"Notifications Successful."
|
"Notifications Successful."
|
||||||
@@ -59,7 +59,7 @@ class Mailer(private val smtp: Smtp) extends Notifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def send(to: String, subject: String, htmlMsg: String, loginAccount: Account, textMsg: Option[String] = None): Unit = {
|
def send(to: String, subject: String, loginAccount: Account, textMsg: String, htmlMsg: 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)
|
||||||
@@ -84,9 +84,9 @@ class Mailer(private val smtp: Smtp) extends Notifier {
|
|||||||
}
|
}
|
||||||
email.setCharset("UTF-8")
|
email.setCharset("UTF-8")
|
||||||
email.setSubject(subject)
|
email.setSubject(subject)
|
||||||
email.setHtmlMsg(htmlMsg)
|
email.setTextMsg(textMsg)
|
||||||
textMsg.foreach{ msg =>
|
htmlMsg.foreach { msg =>
|
||||||
email.setTextMsg(msg)
|
email.setHtmlMsg(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
email.addTo(to).send
|
email.addTo(to).send
|
||||||
@@ -94,6 +94,6 @@ class Mailer(private val smtp: Smtp) extends Notifier {
|
|||||||
|
|
||||||
}
|
}
|
||||||
class MockMailer extends Notifier {
|
class MockMailer extends Notifier {
|
||||||
def toNotify(subject: String, htmlMsg: String, textMsg: Option[String] = None)
|
def toNotify(subject: String, textMsg: String, htmlMsg: 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