You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

90 lines
1.9 KiB

  1. :mod:`email_lib` --- Email
  2. ==========================
  3. .. module:: email_lib
  4. :synopsis: Email library
  5. Email object
  6. ------------
  7. .. class:: Email(self, sender='', recipients=[], subject='')
  8. Wrapper on the email module. Email object represents emails to be sent to the client.
  9. Also provides a clean way to add binary `FileData` attachments
  10. .. attribute:: sender
  11. sender's email
  12. .. attribute:: reply_to
  13. [Optional] if reply_to is not same as sender
  14. .. attribute:: recipients
  15. `list` of recipients or a string separated by comma (,) or semi-colon (;)
  16. .. attribute:: subject
  17. email subject
  18. .. attribute:: msg
  19. message object `email.mime.multipart.MIMEMultipart`
  20. .. attribute:: cc
  21. `list` of cc email ids
  22. .. method:: set_message(message, mime_type='text/html')
  23. append the message with MIME content
  24. .. method:: attach(file_id)
  25. attach a file from the `FileData` table
  26. .. method:: validate()
  27. validate the email ids
  28. .. method:: setup()
  29. setup the SMTP (outgoing) server from `Control Panel` or defs.py
  30. .. method:: send()
  31. send the message
  32. .. method:: validate_email_add(email_id)
  33. Validate the email id
  34. .. method:: sendmail(recipients, sender='', msg='', subject='[No Subject]', parts=[], cc=[], attach=[])
  35. Short cut to method to send an email
  36. Example
  37. -------
  38. Email with attachments::
  39. # get attachments
  40. al = sql('select file_list from `tab%s` where name="%s"' % (dt, dn))
  41. if al:
  42. al = al[0][0].split('\n')
  43. # create the object
  44. email = server.EMail('test@webnotestech.com', ['a@webnotestech.com', 'b@webnotestech.com'], 'this is a test')
  45. # add some intro
  46. email.set_message(replace_newlines('Hi\n\nYou are being sent %s %s\n\nThanks' % dt, dn))
  47. # add attachments
  48. for a in al:
  49. email.attach(a.split(',')[0])
  50. # send
  51. email.send()