The pywebfaction API¶
Basic Usage¶
The API is interacted with via the class WebFactionAPI, which takes a username and password, and connects to WebFaction for you.
from pywebfaction import WebFactionAPI
api = WebFactionAPI(username, password)
emails = api.list_emails()
Available Methods¶
list_emails¶
list_emails takes no arguments, and give you back a list of objects representing the email addresses set up in your WebFaction account, along with what they do (i.e. whether they go to a local mailbox, or are forwarded elsewhere).
Usage is:
from pywebfaction import WebFactionAPI
api = WebFactionAPI(username, password)
emails = api.list_emails()
for email in emails:
print email.address
print email.mailboxes
print email.forwards_to
create_email¶
create_email takes an email address, and sets up a standard email address in your WebFaction account, including creation of a local mailbox for storing your email. It takes a single argument (the email address to create), and returns a response object containing the mailbox name and password (which you’ll need for setting up your email client), and the ID of the email address created.
Any errors encountered will raise a WebFactionFault exception, except for the case where the provided email address is empty, or contains no characters that are valid as part of the generated mailbox name (in this case, ValueError will be raised).
Usage is:
from pywebfaction import WebFactionAPI, WebFactionFault
try:
api = WebFactionAPI(username, password)
response = api.create_email('dominic@example.com')
print response.mailbox
print response.password
print response.email_id
except WebFactionFault as e:
print e.exception_type # e.g. 'DataError'
print e.message # e.g. 'Mailbox with this Name already exists.'
create_email_forwarder¶
create_email_forwarder takes two arguments - an email address to forward emails from, and a list of email addresses to forward to, and sets up a corresponding entry in your WebFaction account. The returned value is the ID of the resulting email address in WebFaction.
Usage is:
from pywebfaction import WebFactionAPI
api = WebFactionAPI(username, password)
email_id = api.create_email_forwarder(
'dominic@example.com',
['barry@example.org', 'lucy@example.net', ]
)
print email_id