Search code examples
pythonmailjet

MailJet | how to Send Mail with Python using variables in text part?


I want to add "print (variable_name)" to the following statement:

'Text-part': 'Dear passenger, welcome to Mailjet! May the delivery force be with you!',

How can it be done?

Following is the Python code:

from mailjet_rest import Client
import os

data = {
        'FromEmail': '****@****.com',
        'FromName': '****',
        'Subject': 'Available DB Names:', #Subject
        'Text-part': 'Dear passenger, welcome to Mailjet! May the delivery 
         force be with you!',
         'Recipients': [{ "Email": "****@****.com"}]
          }
         result = mailjet.send.create(data=data)
         print (result.status_code)
         print (result.json())

Thanks in advance


Solution

  • I assume you want something like this?

    data = {
            'FromEmail': '****@****.com',
            'FromName': '****',
            'Subject': 'Available DB Names:', #Subject
            'Text-part': 'Dear {}, welcome to Mailjet! May the delivery 
             force be with you!'.format(variable_name),
             'Recipients': [{ "Email": "****@****.com"}]
              }