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 = 'email@example.com', replyName = 'James Gardner', replyEmail = 'firstname.lastname@example.org', 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 = 'email@example.com', replyName = 'James Gardner', replyEmail = 'firstname.lastname@example.org', 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.
|msg, to, [subject=''], [method], [smtp], [sendmail], [blind], [reply], [replyName], [replyEmail], [type])|
'sendmail'. Only needs to be specified if both
sendmailare specified otherwise the method that is defined is used.
Trueif recipients are to be blocked from seeing who else the email was sent to.
"sender name <email@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, 'firstname.lastname@example.org') James Gardner <email@example.com>
'plain'for a plain text email,
'html'for an HTML email.