1.10 web.mail -- Simple function to send email using email

The mail module provides a simple function send() which can be used to send emails as shown in the example below:

import web.mail
web.mail.send(
    msg        = "Hello James!",
    to         = 'james@example.com',
    replyName  = 'James Gardner',
    replyEmail = 'james@example.com',
    subject    = 'Test Email',
    sendmail   = '/usr/bin/sendmail',
    method     = 'sendmail'
)

To send the same email via SMTP instead of using Sendmail you would use:

import web.mail
web.mail.send(
    msg        = "Hello James!",
    to         = 'james@example.com',
    replyName  = 'James Gardner',
    replyEmail = 'james@example.com',
    subject    = 'Test Email',
    smtp       = 'smtp.ntlworld.com',
    method     = 'smtp'
)

If you get an error like socket.error: (10060, 'Operation timed out') it is likely that the SMTP address you specified either doesn't exist or will not give you access.

Function Definition:

mail( msg, to, [subject=''], [method], [smtp], [sendmail], [blind], [reply], [replyName], [replyEmail], [type])
msg
Text of the message

to
A list of recipient addresses in the form: addr@addr.com separated by commas

subject
Email subject line

method
Describes which method to use to send the email. Can be 'smtp' or 'sendmail'. Only needs to be specified if both smtp and sendmail are specified otherwise the method that is defined is used.

smtp
SMTP server address

sendmail
Sendmail path

blind
True if recipients are to be blocked from seeing who else the email was sent to.

replyName
The name of the person sending the email.

replyEmail
The address of the person sending the email.

reply
The name and address of the person sending the email in the form: "sender name <addr@example.com>". Should only be specified if replyName and replyEmail are not specified.

The module also provides a method buildReply() which can be used to put the name and email address into the format required for the reply parameter of the send() method:

>>> import web.mail
>>> web.mail.buildReply('James Gardner, 'james@example.com')
James Gardner <james@example.com>

type
The second part of the content-type, eg 'plain' for a plain text email, 'html' for an HTML email.



Subsections