我想从 String 设置 Html 电子邮件的正文,而不是 Lift Mailer 的 Xml 节点,所以我将 Mailer 子类化并重新定义了buildMailBody
方法:
class HtmlMailer extends Mailer {
final case class HtmlMailBodyType(text: String) extends MailBodyType
override protected def buildMailBody(tab: MailBodyType) = {
tab match {
case HtmlMailBodyType(text) =>
val bp = new MimeBodyPart
bp.setText(text, charSet, "html")
bp
case _ => super.buildMailBody(tab)
}
}
}
object HtmlMailer extends HtmlMailer
当我尝试使用它时:
import net.liftweb.util.Mailer
import Mailer._
HtmlMailer.sendMail(From(sender.email), Subject(subject), To(user.email), HtmlMailBodyType(body))
我得到编译错误:
error: type mismatch;
found : net.liftweb.util.Mailer.From
required: com.mypackage.HtmlMailer.From
Error occurred in an application involving default arguments.
HtmlMailer.sendMail(From(sender.email), Subject(subject), To(user.email), HtmlMailBodyType(body))
为什么会发生这种情况,我该如何正确解决?
我将 import Mailer._ 更改为 import HtmlMailer._ 并且它有效,但我相信它违反了 Liskov 替换原则,因为我不能替换HtmlMailer
,Mailer
因为它们有不同的参数类型?