1.9.1 Example

Below is an example demonstrating some of the features which you can use to test the module:

#!/usr/bin/env python

"Test program to send mail to recipients."

import sys
sys.path.append('../')

import web.mail

testAddr = raw_input('Email address to recieve tests: ')
if raw_input('Run the 6 SMTP tests:  [y/n] ') == 'y':
    smtp = raw_input('SMTP server address: ')
    print "Running SMTP Test...."
    counter = 1
    for blind in [True, False]:
        for to in [testAddr, [testAddr], [testAddr,testAddr]]:
            web.mail.send  (
                msg="Hello User!\n\nBlind: " + str(blind),
                to=to,
                reply=web.mail.buildReply('web.mail Test',testAddr),
                subject="SMTP Test "+ str(counter),
                smtp=smtp,
                blind=blind,
                method='smtp'
            )
            print "Sent message %s."%counter
            counter += 1
    print "Done... check your mail!\n"

if raw_input('Run the 6 sendmail tests: [y/n] ') == 'y':
    
    sendmail = raw_input("Sendmail Path (usually /usr/lib/sendmail): ")

    print "Running SMTP Test...."
    counter = 1
    for blind in [True, False]:
        for to in [testAddr, [testAddr], [testAddr,testAddr]]:
            lemon.mail  (
                            msg="Hello User!\n\nBlind: " + str(blind),
                            to=to,
                            reply=web.mail.buildReply('web.mail Test',testAddr),
                            subject="Sendmail Test "+ str(counter),
                            sendmail=sendmail,
                            blind=blind,
                            method='sendmail'
                        )
            print "Sent message %s."%counter
            counter += 1
    print "Done... check your mail!"

See Also:

email Module Documentation
The email module distributed with Python has a much broader API for constructing emails and should be consulted if you plan to anything complicated such as emailing attachements.

See About this document... for information on suggesting changes.