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
Add this import statement to the top of your cloudbolt plugin:
from utilities.mail import email
Add all your email info into variables
Add a list of addresses with:
addresses = [“testemail@gmail.com”, “testemail2@gmail.com”]
Add the email context with:
context = {"group": group}
You can also add
”message”: “This is a test message”
to the context dict to send a basic message in the email
Add the attachments with:
attachments = [('report.zip', zip_contents, 'application/zip')]
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
You can now call the email function to send the email:
email( recipients=addresses, slug="export-group-servers-report", context=email_context, attachments=attachments, )
0 Comments