邮递 |如何在文本部分使用变量发送 Python 的邮件?

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

我想将 "print (variable_name)" 添加到以下语句中:

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

如何做到?

以下是 Python 代码:

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())

提前致谢

我猜你想要这样的东西?

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"}]
          }

不要忘记在调用中声明您的 vars 部分。那就是您要为自定义变量赋值。

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

并且 HTML-Part 或 Text-Part 中的占位符看起来像 {{var:day}} 一样,它将被收件人端的自定义变量的值替换。