Skip to content

Instantly share code, notes, and snippets.

@ermshiperete
Created October 11, 2024 09:12
Show Gist options
  • Select an option

  • Save ermshiperete/a92510c10c1381e823a1a3813353123d to your computer and use it in GitHub Desktop.

Select an option

Save ermshiperete/a92510c10c1381e823a1a3813353123d to your computer and use it in GitHub Desktop.
Brevo python example
#!/usr/bin/python3
# Installation:
# - Create virtual environment with `virtualenv .venv`
# - activate it `. .venv/bin/activate`
# - install brevo-python: `pip3 install brevo-python`
# - API key needs to be in BREVO_API_KEY environment variable
import os
import brevo_python
from brevo_python.rest import ApiException
if not 'BREVO_API_KEY' in os.environ:
print('Error: Environment variable BREVO_API_KEY not set')
exit(1)
# print('API key: ' + os.environ['BREVO_API_KEY'])
# Instantiate the client
configuration = brevo_python.Configuration()
configuration.api_key['api-key'] = os.environ['BREVO_API_KEY']
configuration = brevo_python.Configuration()
configuration.api_key['partner-key'] = os.environ['BREVO_API_KEY']
api_instance = brevo_python.EmailCampaignsApi()
# Define the campaign settings\
email_campaigns = brevo_python.CreateEmailCampaign(
name= 'Campaign sent via the API',
subject= 'My subject',
sender= { 'name': os.environ['BREVO_EMAIL_NAME'], 'email': os.environ['BREVO_EMAIL_ADDRESS'] },
# Content that will be sent
html_content= 'Congratulations! You successfully sent this example campaign via the Brevo API.',
)
# Make the call to the client
try:
# Create an email campaign
api_response = api_instance.create_email_campaign(email_campaigns)
print(api_response)
except ApiException as e:
print("Exception when calling EmailCampaignsApi->create_email_campaign: %s\n" % e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment