TeenvioAPI
is a Python class that provides an interface to interact with the Teenvio email marketing API. It allows users to:
- Authenticate and establish a session
- Create newsletters
- Create recipient groups
- Add recipients to a group
- Send email campaigns
This module requires requests
for making API calls. Install it using:
pip install requests
from teenvio_api import TeenvioAPI
api = TeenvioAPI()
username = "your_username"
password = "your_password"
host = "https://<api_teenvio_url>"
if api.GetSession(username, password, host):
print("Authenticated successfully!")
else:
print("Authentication failed!")
newsletter_name = "My Newsletter"
newsletter_html = "<h1>Welcome to our newsletter!</h1>"
newsletter_id = api.CreateNewsletter(newsletter_name, newsletter_html)
if newsletter_id:
print(f"Newsletter created successfully with ID: {newsletter_id}")
else:
print("Failed to create newsletter")
group_name = "Subscribers"
recipients = ["user1@example.com", "user2@example.com"]
group_id = api.CreateGroup(group_name, recipients)
if group_id:
print(f"Group created successfully with ID: {group_id}")
else:
print("Failed to create group")
campaign_name = "New Product Launch"
sender_id = "12345" # sender id in teenvio
replyto = "12345" # None or sender id in teenvio
subject = "Introducing our new product!"
lang_id = "4" # Languages code in teenvio {'ca': '15', 'en': '4', 'es': '3'}
campaign_id = api.SendCampaign(
campaign_name, sender_id, replyto, subject, newsletter_id, group_id, lang_id
)
if campaign_id:
print(f"Campaign sent successfully with ID: {campaign_id}")
else:
print("Failed to send campaign")
The class uses Python's logging
module to log errors and responses. To enable logging, configure it as follows:
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
This project is licensed under the MIT License.