Table Of Contents

Previous topic

utils — Utilities Module

Next topic

profile — Profile

This Page

email_lib — Email

Email object

class email_lib.Email(self, sender='', recipients=[], subject='')

Wrapper on the email module. Email object represents emails to be sent to the client. Also provides a clean way to add binary FileData attachments

sender
sender’s email
reply_to
[Optional] if reply_to is not same as sender
recipients
list of recipients or a string separated by comma (,) or semi-colon (;)
subject
email subject
msg
message object email.mime.multipart.MIMEMultipart
cc
list of cc email ids
set_message(message, mime_type='text/html')
append the message with MIME content
attach(file_id)
attach a file from the FileData table
validate()
validate the email ids
setup()
setup the SMTP (outgoing) server from Control Panel or defs.py
send()
send the message
email_lib.validate_email_add(email_id)
Validate the email id
email_lib.sendmail(recipients, sender='', msg='', subject='[, No Subject], ', parts=[], cc=[], attach=[])
Short cut to method to send an email

Example

Email with attachments:

# get attachments
al = sql('select file_list from `tab%s` where name="%s"' % (dt, dn))
if al:
        al = al[0][0].split('\n')

# create the object
email = server.EMail('test@webnotestech.com', ['a@webnotestech.com', 'b@webnotestech.com'], 'this is a test')

# add some intro
email.set_message(replace_newlines('Hi\n\nYou are being sent %s %s\n\nThanks' % dt, dn))

# add attachments
for a in al:
        email.attach(a.split(',')[0])

# send
email.send()