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 = 'firstname.lastname@example.org', replyName = 'James Gardner', replyEmail = 'email@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 = 'firstname.lastname@example.org', replyName = 'James Gardner', replyEmail = 'email@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.
|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 <firstname.lastname@example.org>". 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, 'email@example.com') James Gardner <firstname.lastname@example.org>
'plain'for a plain text email,
'html'for an HTML email.