0

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

Roman Patutin
  • 2,171
  • 4
  • 23
  • 27
noamsh88
  • 39
  • 6

2 Answers2

0

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"}]
          }
Josh Friedlander
  • 10,870
  • 5
  • 35
  • 75
  • Thanks a lot for your answer, correct, finally worte following and it worked for me: 'Text-part': 'Dear {}, welcome to Mailjet! May the delivery ' + str(variable_name) – noamsh88 Mar 14 '19 at 10:23
  • @Josh Friedlander why do you cast to `str()` before passing into `format()`? You're ruining all the goodness that `format()` has to offer! – Nils Werner Apr 02 '19 at 08:29
  • @NilsWerner thanks for pointing that out. As you'll see in the edit history, my original answer didn't include `str` - not sure why I changed it, but I've reverted it now... – Josh Friedlander Apr 02 '19 at 10:09
0

Do not forget to also declare your vars section within the call. That is were you would give a value to your custom variables.

"Variables": {
                                "day": "Monday"
                        }

And the placeholder within the HTML-Part or Text-Part would look as such {{var:day}} which would be replaced by the value of your custom variable at the recipients end.

Krass
  • 86
  • 1
  • 7