AuthとMail

□未翻訳

□翻訳中

□翻訳完了(中垣健志)

■レビュー(細田謙二)

AuthMail

Auth and Mail

デフォルトでは、メールアドレスによる検証は無効になっています。メールアドレスの検証を有効にするには、以下のコードを auth が定義してあるモデルに追加してください。

By default, email verification is disabled. To enable email, append the following lines in the model where auth is defined:

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

11.

12.

13.

14.

15.

16.

17.

from gluon.tools import Mail

mail = Mail(globals())

mail.settings.server = 'smtp.example.com:25'

mail.settings.sender = 'you@example.com'

mail.settings.login = 'username:password'

auth.settings.mailer = mail

auth.settings.registration_requires_verification = False

auth.settings.registration_requires_approval = False

auth.settings.reset_password_requires_verification = True

auth.messages.verify_email = 'Click on the link http://' + \

request.env.http_host + \

URL(r=request,c='default',f='user',args=['verify_email']) + \

'/%(key)s to verify your email'

auth.messages.reset_password = 'Click on the link http://' + \

request.env.http_host + \

URL(r=request,c='default',f='user',args=['reset_password']) + \

'/%(key)s to reset your password'

mail.settingは、利用するSMTPサーバに対して適したパラメタに置き換える必要があります。SMTPサーバが認証を必要としない場合は、mail.settings.login=False と設定してください。

You need to replace the mail.settings with the proper parameters for your SMTP server. Setmail.settings.login=False if the SMTP server does not require authentication.

以下の文字列...は、

You also need to replace the string

1.

'Click on the link ...'

auth.messages.verify_email にありますが、これをverify_emailのアクションの正しい完全なURLに置き換える必要があります。 なぜなら、web2pyはプロキシの下にインストールされているかもしれず、自身の公開URLを確実に決定することができないからです。

in auth.messages.verify_email with the proper complete URL of the action verify_email. This is necessary because web2py may be installed behind a proxy, and it cannot determine its own public URLs with absolute certainty.

mail.send

一旦 mail が定義されていれば, 以下のように明示的にメールを送ることもできます。

Once mail is defined, it can also be used to send email explicitly via

1.

2.

3.

4.

5.

mail.send(to=['somebody@example.com'],

subject='hello',

# If reply_to is omitted then mail.settings.sender is used

reply_to='us@example.com',

message='hi there')

メールの送信に成功した時にはTrueを、失敗すればFalseを返します。mail.send() の引数のより完全な一覧を次に示します。

Mail returns True if it succeeds in sending the email, False otherwise. A more complete argument list for mail.send() is as follows:

1.

2.

send(self, to, subject='None', message='None', attachments=1,

cc=1, bcc=1, reply_to=1, encoding='utf-8')

メールのデバッグ

Email Debugging

email logging

デバッグ目的のために、次のような設定を行うことができます。

For debugging purposes you can set

1.

mail.settings.server = 'logging'

このとき、メールは実際には送信されず、代わりにコンソールに表示されます。

and emails will not be sent but logged to console instead.

Google App Engineからメールを送信する

Emails from Google App Engine

email from GAE

Google App Engineのアカウントからメールを送信するには次のようにします:

For sending emails from Google App Engine account:

1.

mail.settings.server = 'gae'

このマニュアルを書いている時点では、web2pyはGoogle App Engine上でのファイル添付や暗号化などをサポートしていません。

At the time of writing web2py does not support attachments and encrypted emails on Google App Engine.

その他のメール処理のサンプル

More Email Examples

email html

email attachments

シンプルなテキストメール

Simple text email

1.

2.

3.

mail.send('you@example.com',

'Message subject',

'Plain text body of the message')

HTMLメール

HTML emails

1.

2.

3.

mail.send('you@example.com',

'Message subject',

<html>html body</html>)

メール本文が <html> で始まり </html> で終わる場合、HTMLメールとして送信されます。

If the email body starts with <html> and ends with </html> it will be sent as a HTML email.

テキストとHTMLの混合メール

Combining Text and HTML Emails

メールのメッセージは、テキストとHTMLのタプルにすることができます。

The email message can be a tuple (text, html):

1.

2.

3.

mail.send('you@example.com',

'Message subject',

('Plain text body', '<html>html body</html>'))

CCとBCC

CC and BCC Emails

1.

2.

3.

4.

5.

mail.send('you@example.com',

'Message subject',

'Plain text body',

cc=['other1@example.com', 'other2@example.com'],

bcc=['other3@example.com', 'other4@example.com'])

添付

Attachments

1.

2.

3.

4.

mail.send('you@example.com',

'Message subject',

'<html><img src="cid:photo" /></html>',

attachments = Mail.Attachment('/path/to/photo.jpg', content_id='photo'))

複数ファイルの添付

Multiple attachments

1.

2.

3.

4.

5.

mail.send('you@example.com,

'Message subject',

'Message body',

attachments = [Mail.Attachment('/path/to/fist.file'),

Mail.Attachment('/path/to/second.file')])

x509とPGPによる暗号化

x509 and PGP Encryption

PGP

x509

次の設定により、x509(SMIME)で暗号化されたメールを送信することができます。

It is possible to send x509 (SMIME) encrypted emails using the following settings:

1.

2.

3.

4.

5.

6.

7.

mail.settings.cipher_type = 'x509'

mail.settings.sign = True

mail.settings.sign_passphrase = 'your passphrase'

mail.settings.encrypt = True

mail.settings.x509_sign_keyfile = 'filename.key'

mail.settings.x509_sign_certfile = 'filename.cert'

mail.settings.x509_crypt_certfiles = 'filename.cert'

次の設定により、PGPで暗号化されたメールを送信することができます。

It is possible to send PGP encrypted emails using the following settings:

1.

2.

3.

4.

5.

from gpgme import pgp

mail.settings.cipher_type = 'gpg'

mail.settings.sign = True

mail.settings.sign_passphrase = 'your passphrase'

mail.settings.encrypt = True

後者は、python-pymeパッケージを必要とします。

The latter requires the python-pyme package.