CMP Class

class CSMTP.CMP(sender_mail='', password='', mailhost='localhost', mailport='465')

  • sender_mail: The email that will be used to send the emails. The default value will use the environment variable named ['CSMTP_MAIL'] and if it fails it will raise an Exception
  • password: The password of the email that is parsed to the sender_mail argument. The default value will use the environment variable named ['CSMTP_PASS'] and if it fails it will raise an Exception
  • mailhost: Defaults to localhost but you will need to set up an smtplib Debugging server for the default to work. If a different value is provided it will be parsed to the host argument of the SMTP_SSL class
  • mailport: Defaults to 465, if a different value is used, it will be parsed to the port argument of theSMTP_SSL class

CMP Methods

CMP().send_simple_msg(self, receiver, subject='', body='')

This method will create an EmailMessage object and use the provided values as its arguments. Depending on the CMP instances mailhost attribute, it will send the email to the debugging server if the mailhost is set to localhost otherwise it will use the SMTP_SSL class to send the email(s)

  • receiver: The email that the message/email will be sent to. It can be a list or comma separated string of emails
  • subject: The subject/heading of the message/email. This argument will be assigned to the Subject attribute of the EmailMessage object
  • body: The body text of the message/email. This argument will be parsed in the set_content method of the EmailMessage object

CMP().send_html(self, receiver, html_string, subject='', body='')

This method will create an EmailMessage object and use the provided values as its arguments. Depending on the CMP instances mailhost attribute, it will send the email to the debugging server if the mailhost is set to localhost otherwise it will use the SMTP_SSL class to send the email(s)

  • receiver: The email that the message/email will be sent to. It can be a list or comma separated string of emails
  • subject: The subject/heading of the message/email. This argument will be assigned to the Subject attribute of the EmailMessage object
  • body: The body text of the message/email. This argument will be parsed in the set_content method of the EmailMessage object and will be displayed only if the receiver is unable to render the html.
  • html_string: The html string that will be displayed to the user. This value will be parsed to the add_alternative method of the EmailMessage object. ensure that your css is applied through the html text

CMP().send_special(self, file_dir, receiver, subject='', body='', maintype='')

This method will create an EmailMessage object and use the provided values as its arguments. Depending on the CMP instances mailhost attribute, it will send the email to the debugging server if the mailhost is set to localhost otherwise it will use the SMTP_SSL class to send the email(s)

  • file_dir: The directory to file(s) you will send. It can be a list or comma separated string of directories
  • receiver: The email that the message/email will be sent to. It can be a list or comma separated string of emails
  • subject: The subject/heading of the message/email. This argument will be assigned to the Subject attribute of the EmailMessage object
  • body: The body text of the message/email. This argument will be parsed in the set_content method of the EmailMessage object.
  • maintype: The file type of the files that will be emailed, default is 'image'.Only options are 'image' and 'media'. 'image', use this option when sending image files only. 'media', use this option to send any media files, like videos, images and documents.
  • Ensure that the size of the files that you will be sending comply with the email servers limit.

Errors that may arise are explained in the smtplib docs

It will raise a ValueError if the email(s) you provided are invalid