Skip to content

Latest commit

 

History

History
77 lines (51 loc) · 1.45 KB

README.md

File metadata and controls

77 lines (51 loc) · 1.45 KB

mailer

Setup

Expects a secret in Google Secret manager called: MAILGUN_TOKEN.

TODO: add an option to pull the token from environment as well.

Example Usages:

Sending a simple message

from mailer import Mailer


email = Mailer()
email.recipients = ["[email protected]", "[email protected]"]
email.subject = "This is the subject line"

email.send_message("This is a test message")

Sending a custom HTML message

from mailer import Mailer


email = Mailer()
email.recipients = ["[email protected]", "[email protected]"]
email.subject = "This is the subject line"

html = """
<html>
  <p> Dear Recipient,</p>
  <br>
  <p>This is a <strong>very important</strong> message.</p>
</html>
"""

email.send_html(html)

Sending from a Mailgun template

from mailer import Mailer


email = Mailer()
email.recipients = ["[email protected]", "[email protected]"]
email.cc = ["[email protected]"]
email.subject = "This is the subject line"
email.template = "mailgun_template_name"

email.template_vars = {
    "template_var1": "value1",
    "template_var2": "value2",
}
email.send_template()

Attaching files

from mailer import Mailer


email = Mailer()
email.recipients = ["[email protected]", "[email protected]"]
email.subject = "This is the subject line"
email.files(filepaths=["path_to_file/file_name.pdf"])

email.send_message("This is a test message")