HOWTO: Send an attachment via email from a CloudBolt Plugin

Overview

The purpose of this article is to explain and demonstrate how to send an attachment via email programmatically from a Cloudbolt plugin.

Procedure

Import email function

  1. Add this import statement to the top of your cloudbolt plugin: from utilities.mail import email

Add all your email info into variables

  1. Add a list of addresses with: addresses = [“testemail@gmail.com”, “testemail2@gmail.com”]

  2. Add the email context with: context = {"group": group}

    1. You can also add ”message”: “This is a test message” to the context dict to send a basic message in the email

  3. Add the attachments with: attachments = [('report.zip', zip_contents, 'application/zip')]

    1. Note that the attachments must be a list of tuples, that contains (file_path, file_contents, mime_content_type)

Invoke the email function to send the email

  1. You can now call the email function to send the email:

email(
    recipients=addresses,
    slug="export-group-servers-report",
    context=email_context,
    attachments=attachments,
)

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.