Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8117697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:15:30+00:00 2026-06-06T04:15:30+00:00

I want to set body of Html email from String, not Xml Node for

  • 0

I want to set body of Html email from String, not Xml Node for Lift Mailer, so I subclassed Mailer and redefined buildMailBody method:

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

When I try to use it:

import net.liftweb.util.Mailer
import Mailer._    

HtmlMailer.sendMail(From(sender.email), Subject(subject), To(user.email), HtmlMailBodyType(body))

I get compilation error:

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))

Why is this happeing and how can I fix it correctly?

I changed import Mailer._ to import HtmlMailer._ and it worked, but I beleive it breaks Liskov substitution principle, as I cannot substitute HtmlMailer instead of Mailer, because they have different parameter types?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T04:15:31+00:00Added an answer on June 6, 2026 at 4:15 am

    You are having trouble with path dependent types and singletons. When you have nested classes, each instance of the outer class has a different instance of the nested class.

    Now, the From (plus Subject, To, etc), since they are nested, belong to a specific instance. In this case, you have two instances providing them. They are the objects:

    net.liftweb.util.Mailer
    com.mypackage.HtmlMailer
    

    Note that these are not classes, they are objects.

    Now, the method sendMail requires that its parameters be composed of classes belonging to the same instance as itself. There are many reasons for making such a requirement, as there are ways of not making it.

    So, really, there’s no violation of the liskov substitution principle here, just a violation of type that has been hidden by the import. If you write it out explicitly, it becomes clearer:

    val myInst: net.liftweb.util.Mailer = HtmlMailer
    myInst.sendMail(myInst.From(sender.email), myInst.Subject(subject), myInst.To(user.email), myInst.HtmlMailBodyType(body))
    

    You can replace HtmlMailer there with net.liftweb.util.Mailer or any other instance of net.liftweb.util.Mailer and it will work. You cannot use two different instances of net.liftweb.util.Mailer, even if they are both of the very same class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using MessageUI framework to compose email in my app. I want set HTML
I want to make email templates in Zend Framework. For example, <html> <body> Dear
I haven't set a height to the body - I just want the wrapper
I want set Listbox background to transparent but not working Is there any idea?
I want to set different text formats (normal, bold, italic...) or HTML in the
I want to create a html email and I've read a lot about how
I want to set my homepage's body element clickable in a click through campaing
I want to set up inline content of a WPF WebBrowser control: <WebBrowser> <html>
I have a HTML table where I must set the overall width and want
Can I just build html email as usually we build html pages? I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.