Package: secure-email-lacsd
Secure EmailTable of ContentsProject DescriptionInstallationSetupUsageProject DescriptionThis project allows sending STMP email over TLS using SSL. Use the Emailer class to create an instance for an outgoing email account, and call thesendmethod to send an email. You can also use the EmailHandler class to add a custom email handler to your app's logger.Installationpython -m pip install secure-email-lacsdSetupKeyringThe keyring library stores credentials in your machine's Windows Credential Locker. If you wish to make use of the Emailer class' use_keyring argument, make sure you have thekeyringlibrary installed:pip install keyringTo use keyring to fetch the password in the Emailer class, use the email address associated with the credentials as the name:keyring.set_password("username@domain.com","lacsd.org\\username","supersecretpassword")Usagefrom secure_email.sendmail import EmailerFiles in the demo folder demonstrate how to use the two classes in this project--Emailer and EmailHandler.send_email.pydemonstrates how to send an email from a python script, and theflask_appdemonstrates how to add the EmailHandler to you app's logger. The Emailer and EmailHandler classes are both located insendmail.pyin the src folder.EmailerClass for sending emails. Instantiating a class merely stores the info to create an STMP connection, while calling the send method creates the STMP connection, sends an email, and then closes the connection.Arguments:secure_host (str): default SSL-enabled mail hostport (int): port number for mail hostemail_address (str): "from" email addresspassword: (str | None): email password (default: None)unsecure_host: (str | None): backup non-SSL mail hostuse_keyring (bool): whether to fetch password from keyring (default: False)include_ssl_status (bool): whether to add line to body of sent emails indicating whether email was sent over SSL
(default: False)Methods:sendSends STMP emailArguments:to (str|list[str]): email recipient(s)subject (str): email subject linebody (str): body of email as text or HTML stringcc_list (list[str]): recipients to CC (default: [])bcc_list (list[str]): recipients to BCC (default: [])html (bool): whether to send body as HTML (default: False)secure (bool): whether to send over SSL (default: True)Returns:response (subprocess.CompletedProcess): result returned by cmd.exe after executing email send commandExample:# Supply password directlyemailer=Emailer("my.emailserver.com",# host0,# port"email@example.com",# email_addresspassword="supersecretpassword")# Use password stored in keyringemailer=Emailer("my.emailserver.com",# host0,# port"email@example.com",# email_addressuse_keyring=True)response=emailer.send("recipient@domain.org",# to"Open Immediately!!!",# subject"You may have won $1,000,000. Click the link below to find out",# body)successful=response.stderr!=""exit_code=response.returncode# Successfully sent emails will return an exit code of 0EmailHandlerExtends logging.handlers.SMTPHandler to use theEmailerclass to send emails (see thelogging library documentationto learn more about the SMTPHandler). EmailHandler does not add any new methods to SMTPHandler, but it does take an additional argument.Additional arguments:send_html (bool): whether to send HTML email instead of plain text (default: False)backup_host (str | None): non-SSL host to send from if SSL host failsinclude_ssl_status (bool): whether to add line to body of sent emails indicating whether email was sent over SSL default: False)