Skip to Content
Lift Cookbook
book

Lift Cookbook

by Richard Dallaway
June 2013
Intermediate to advanced
253 pages
5h 5m
English
O'Reilly Media, Inc.
Content preview from Lift Cookbook

Chapter 9. Around Lift

This chapter looks at interacting with other systems from within Lift, such as sending email, calling URLs, or scheduling tasks.

Many of the recipes in this chapter have code examples in a project at https://github.com/LiftCookbook/cookbook_around.

Sending Plain-Text Email

Problem

You want to send a plain-text email from your Lift application.

Solution

Use the Mailer:

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

Mailer.sendMail(
  From("you@example.org"),
  Subject("Hello"),
  To("other@example.org"),
  PlainMailBodyType("Hello from Lift") )

Discussion

Mailer sends the message asynchronously, meaning sendMail will return immediately, so you don’t have to worry about the time costs of negotiating with an SMTP server. However, there’s also a blockingSendMail method if you do need to wait.

By default, the SMTP server used will be localhost. You can change this by setting the mail.smtp.host property. For example, edit src/mail/resources/props/default.props and add the line:

mail.smtp.host=smtp.example.org

The signature of sendMail requires a From, Subject, and then any number of MailTypes:

To, CC, and BCC
The recipient email address
ReplyTo
The address that mail clients should use for replies
MessageHeader
Key/value pairs to include as headers in the message
PlainMailBodyType
A plain-text email sent with UTF-8 encoding
PlainPlusBodyType
A plain-text email, where you specify the encoding
XHTMLMailBodyType
For HTML email (SMTP Authentication)
XHTMLPlusImages ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Lift in Action

Lift in Action

Tim Perrett

Publisher Resources

ISBN: 9781449365042Errata Page