exploring.liftweb.net Sending Email をテキトーに翻訳(暫定)

exploring.liftweb.net 該当ページ
読むのがだるい人は、下のソースだけでも見てみてください。

F Sending Email/メール送信

Sending email is a common enough task (user registration, notifications, etc) within a web application that we’ve decided to cover it here.
電子メール送信は、(私たちがここでそれをカバーすると決定した)ウェブ・アプリケーション内に十分に一般的なタスク(ユーザ登録、通知など)です。

Although email isn’t Lift’s primary focus, Lift does provide some facilities to simplify email transmission.
電子メールはLiftの主な注力対象ではありませんが、電子メール送信を簡易化するいくつかの仕組みを提供します。

F.1 Setup / セットアップ

Configuration of the mailer is handled in a few different ways.
送信者の設定はいくつかの方法で利用できます。

The net.liftweb.util.Mailer object defines a hostFunc function var, () ⇒ String, that is used to compute the hostname of your SMTP server to be used for transmission.
net.liftweb.util.MailerオブジェクトはhostFunc () ⇒ String を定義し, 送信に使用されるSMTPサーバーのホスト名を導き出すために使用されます。

The default value is a function that looks up the mail.smtp.host system property and uses that String.
SMTPサーバのデフォルト値は、システム設定mail.smtp.host を調べて、そのストリングを使用します。

If that property isn’t defined then the mailer defaults to localhost.
もしそのシステム設定が定義されていない場合はlocalhostが使用されます。

Setting the system property is the simplest way to change your SMTP relay, although you could also define your own function to return a custom hostname and assign it to Mailer.hostFunc.
mail.smtp.hostへのシステムへ設定がSMTP定義を使用する最も簡単な方法ですが、カスタム・ホスト名を返すオリジナルの関数をMailer.hostFuncに定義することもできます。

F.2 Sending Emails / メール送信

The mailer interface is simple but covers a wide variety of cases.
Mailerインターフェースは単純であるが、様々なケースをカバーできます。

The Mailer object defines a number of case classes that correspond to the components of an RFC822 email.
Mailerオブジェクトは、RFC822電子メールのコンポーネントに相当する多くのケース・クラスを定義します。

The addressing and subject cases classes, From, To, CC, BCC, ReplyTo and Subject should all be self-explanatory.
アドレシングおよびサブジェクトケース・クラス、From, To, CC, BCC, ReplyTo および Subjectはすべて使用することが出来ます。

For the body of the email you have three main options:
電子メールのBodyについては、3つのメイン・オプションを持っています:

  • PlainMailBodyType / プレーンメールタイプ
    Represents a plain-text email body based on a given String
    与えられた文字列に基づくプレインテキストメール
  • XHTMLMailBodyType / XHTMLメールタイプ
    Represents an XHTML email body based on a given NodeSeq
    与えられたNodeSeqに基づくXHTMLメール(HTMLメール)
  • XHTMLPlusImages
    Similar to XHTMLMailBodyType, but in addition to the NodeSeq, you can provide one or more PlusImageHolder instances that represent images to be attached to the email (embedded images, so to speak)
    XHTMLMailBodyTypeの付加機能版。NodeSeqに一つ以上のイメージなどをメールにアタッチできるPlusImageHolderインスタンスを付加できる。

The Mailer.sendMail function is used to generate and send an email.
Mailer.sendMail関数はメールの生成と送信のために使用される。

It takes three arguments: the From sender address, the Subject of the email, and a varargs list of recipient addresses and body components.
3つの引数をとります。:Fromは送信者アドレス、Subjectはメールの主題、そして可変長引数のリスト(受信アドレス、bodyコンポーネントなど)。

The mailer creates MIME/Multipart messages, so you can send more than one body (i.e. plain text and XHMTL) if you would like.
Mailer は MIME/Multipart メッセージを生成するので、一つ以上のボディ(i.e. プレインテキストとXHMTL)を含むメールを送信できます。

Listing F.2↓ shows an example of sending an email to a group of recipients in both plain text and XHTML format.
F.2↓ 受信者グループに、プレインテキストとXHTMLの二つのフォーマットを持つメールを送信する例を以下に示します。

The Mailer object defines some implicit conversions to PlainMailBodyType and XHTMLMailBodyType, which we use here.
Mailerオブジェクトは暗黙的なプレインテキストとXHTML形式の変換を定義する。

We also have to do a little List trickery to be able to squeeze multiple arguments into the final vararg argument since Scala doesn’t support mixing regular values and coerced sequences in vararg arguments.
我々はまた、Scalaは引数を可変引数に正規値と強要されたシーケンスを混在をサポートしていませんので、最後の可変引数の引数に複数の引数を絞ることができるために少しリストのトリックを行う必要があります。

Sending a two-part email
1
2
3
4
5
6
7
8
9
import net.liftweb.util.Mailer
import Mailer._
...
val myRecips : List[String] = ...
val plainContent : String = "..."
val xhtmlContent : NodeSeq = ...
​
Mailer.sendMail(From("no-reply@foo.com"), Subject("Just a test"),
                (plainContent :: xhtmlContent :: myRecips.map(To(_))) : _*)

When you call sendMail you’re actually sending a message to an actor in the background that will handle actual mail delivery;
sendMailを呼ぶ場合、実際のメール配信をバックグラウンドで処理するアクターにメッセージを送っている。

because of this, you shouldn’t expect to see a synchronous relay of the message through your SMTP server.
このため、あなたのSMTPサーバーを介してメッセージを同期的に中継を見られることを期待してはいけません。

(C) 2011 Lift 2.0 EditionWritten by Derek Chen-Becker, Marius Danciu and Tyler Weir

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください