import sendpulse
from sendpulse.rest_api import ApiException
from sendpulse.smtpapi import SmtpApiSender
# API keys for SendPulse
SP_API_USER_ID = 'your_api_user_id'
SP_API_SECRET = 'your_api_secret'
# Function for sending messages
def send_message(recipient, message):
sp_api_client = sendpulse.Sendpulse(
SP_API_USER_ID,
SP_API_SECRET,
None
)
email = {
'html': message,
'subject': 'Название вашей кампании',
'from': {
'name': 'Ваше имя',
'email': 'ваш_email@ваш_домен'
},
'to': [
{
'name': recipient['name'],
'email': recipient['email']
}
]
}
# Sending message via SMTP
sender = SmtpApiSender(SP_API_USER_ID, SP_API_SECRET)
try:
result = sp_api_client.smtp_send_mail(email, sender)
print(result)
except ApiException as e:
print(e)
# Function for sending subscription messages
def send_subscription_message(recipient):
message = f"Спасибо за подписку на нашу рассылку! Мы подготовили для вас маленький подарок. Скачайте его по ссылке."
send_message(recipient, message)
# Function for sending webinar messages