def send(**kwargs): try: mailchimp = MailchimpTransactional.Client(os.environ.get('MAILCHIMP')) response = mailchimp.messages.send({"message": kwargs}) print(response) except ApiClientError as error: print("An exception occurred: {}".format(error.text))
def run(): try: mailchimp = MailchimpTransactional.Client('YOUR_API_KEY') response = mailchimp.users.ping() print('API called successfully: {}'.format(response)) except ApiClientError as error: print('An exception occurred: {}'.format(error.text))
def workflow(_request: dict, settings: dict) -> None: """ WORKFLOW to send an email to a profile after catching a wehook parsing success event @rtype: null @param _request: dictionary that contains the body and the headers of the request @param settings: dictionary of settings params of the workflow """ if not _request.get("profile"): return webhook_event = get_profile_event(_request) assert webhook_event[ "type"] == "profile.parsing.success" # This workflow is only to create a new profile verify_webhook(_request["HTTP-HRFLOW-SIGNATURE"], webhook_event, settings["HRFLOW_WEBHOOK_SECRET"]) profile_key = webhook_event["profile"]["key"] source_key = webhook_event["profile"]["source"]["key"] # Retrieve Profile from HrFlow.ai hrflow_client = Hrflow(api_secret=settings["HRFLOW_API_SECRET"], api_user=settings["HRFLOW_API_USER"]) profile = hrflow_client.profile.indexing.get(source_key=source_key, key=profile_key).get("data") assert profile is not None # send Email with Mailchimp mailchimp = MailchimpTransactional.Client(settings["MANDRILL_API_TOKEN"]) message = { "from_email": settings["HRFLOW_API_USER"], "subject": "Thank you for your application", "text": "Your application is well received. Our team will reach out to you if there are any opportunities " "matching your profile. Best, the Team", "to": [{ "email": profile["info"]["email"], "type": "to" }] } try: response = mailchimp.messages.send({"message": message}) print("AcPI called successfully: {}".format(response)) except ApiClientError as error: print("An excception occurred: {}".format(error.text))
def _send_message(recipients: list, subject: str, from_email: str, template: str, variables: list, bcc_address: str = None) -> dict: _validate_recipients(recipients) _validate_template(template, variables) client = mailchimp_transactional.Client(get_mailchimp_api_key()) return client.messages.send_template( { "template_name": template, "template_content": [], # For backward compatibility reason, just an empty array "message": { "to": recipients, "subject": subject, "from_email": from_email, "merge_language": "handlebars", "global_merge_vars": variables, "bcc_address": bcc_address } } )
import mailchimp_transactional as MailchimpTransactional from mailchimp_transactional.api_client import ApiClientError mailchimp = MailchimpTransactional.Client('YOUR_API_KEY') def run(): try: response = mailchimp.subaccounts.resume({ "id": "UNIQUE_ACCOUNT_ID" }) print("This subaccount is now {} ".format(response['status'])) except ApiClientError as error: print('An exception occurred: {}'.format(error.text)) run()
def __init__(self): self.client = MailchimpTransactional.Client(self.api_key)
def get_mailchimp_client(): return MailchimpTransactional.Client(get_mail_chimp_api_key())
def create(self): """ set MailChimp_API_KEY change tokens list to dictionary's that service needs for tokens space in content if token phone_number have [] or '' delete that change signs of tokens space to signs's service needs if want send difference contents to receivers so it set settings for it create message parameter for send email Parameter --------- to: list list of {"email": receiver, "type": 'to'} API_KEY: str MailChimp Api Key mailchimp: mailchimp client parameter message: dict { "from_email": email of sender, "subject": subject, "text": content, "to": to list, "merge_vars": self.tokens, } template_content: list [{"name":name of template's block, "content": content}] """ self.to = [] self.vars = [] self.tokens = [] self.API_KEY = 'EWV8qx2JRA6JcdYwEAEQ8g' self.mailchimp = MailchimpTransactional.Client(self.API_KEY) i = 0 for tokens in self.tokens_list: for key in tokens: if key == "phone_number": try: if (tokens[key].count("[") and tokens[key].count("]")) == 1: if tokens[key].count("'") == 2: tokens[key] = tokens[key][2:-2] else: tokens[key] = tokens[key][1:-1] except: pass self.vars.append({"name": key, "content": tokens[key]}) self.tokens.append({ 'rcpt': self.to_receivers[i], 'vars': self.vars }) i = +1 self.vars = [] if type(self.to_receivers) != list: x = [self.to_receivers] self.to_receivers = x #-------------------------------------------------------- if self.tokens != []: try: temp_content = self.content.replace('{', "{{") self.content = temp_content.replace('}', "}}") except: pass if type(self.content) == list: if self.content[1] != None: if self.content[0] != self.content[1]: self.content = "{{content}}" else: self.content = self.content[0] else: self.content = self.content[0] self.template_content = [{"name": "main", "content": self.content}] for receiver in self.to_receivers: self.to.append({"email": receiver, "type": 'to'}) self.message = { "from_email": self.from_sender, "subject": self.subject, "text": self.content, "to": self.to, "merge_vars": self.tokens, }
import mailchimp_transactional as MailchimpTransactional from mailchimp_transactional.api_client import ApiClientError import os from dotenv import load_dotenv load_dotenv() try: client = MailchimpTransactional.Client(os.getenv('TRANSACTIONAL_KEY')) response = client.users.ping() print('client.users.ping() response: {}'.format(response)) except ApiClientError as error: print('An exception occurred: {}'.format(error.text)) try: client = MailchimpTransactional.Client() client.set_api_key(os.getenv('TRANSACTIONAL_KEY')) response = client.users.ping() print('client.users.ping() response: {}'.format(response)) except ApiClientError as error: print('An exception occurred: {}'.format(error.text))