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:
msg, to, [subject=''], [method], [smtp], [sendmail], [blind], [reply], [replyName], [replyEmail], [type]) |
'smtp'
or 'sendmail'
. Only needs to be specified if both smtp
and sendmail
are specified otherwise the method that is defined is used.
True
if recipients are to be blocked from seeing who else the email was sent to.
"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>
'plain'
for a plain text email, 'html'
for an HTML email.