1

我想使用“SendInBlue”发送交易和营销电子邮件。我也想用 Python 语言来做同样的事情。我访问了 SendInBlue 的 API 文档并遵循相同的程序,仍然无法发送电子邮件。

from mailin import Mailin
    m = Mailin("https://api.sendinblue.com/v2.0","ScrWGqd296ya0CWq")
    data = { "to" : {"aman@gmail.com":"to whom!"},
        "from" : ["amandeep@gmail.com", "from email!"],
        "subject" : "Subject...",
        "html" : "This is the <h1>HTML</h1>",
        "attachment" : ["https://example.com/path-to-file/filename1.pdf", "https://example.com/path-to-file/filename2.jpg"]
    }

    result = m.send_email(data)
    print(result)

我还从 github 下载了 mailin-api-python 并运行了这个脚本。我不知道在哪里设置我的 smtp 详细信息。

**出于安全目的,我更改了 API 密钥。

4

1 回答 1

1

我强烈建议您使用最新版本的 SendinBlue 的 Python 包装器,他们提供了一个示例

from __future__ import print_function
import time
import sib_api_v3_sdk
from sib_api_v3_sdk.rest import ApiException
from pprint import pprint

# Configure API key authorization: api-key
configuration = sib_api_v3_sdk.Configuration()
configuration.api_key['api-key'] = 'API-KEY'

# create an instance of the API class
api_instance = sib_api_v3_sdk.SMTPApi(sib_api_v3_sdk.ApiClient(configuration))
senderSmtp = sib_api_v3_sdk.SendSmtpEmailSender(name="test",email="youremail@gmail.com")
sendTo = sib_api_v3_sdk.SendSmtpEmailTo(email="recipientEmail@gmail.com",name="Recipient Name")
arrTo = [sendTo] #Adding `to` in a list
send_smtp_email = sib_api_v3_sdk.SendSmtpEmail(sender=senderSmtp,to=arrTo,html_content="This is a test",subject="This is a test subject") # SendSmtpEmail | Values to send a transactional email

try:
    # Send a transactional email
    api_response = api_instance.send_transac_email(send_smtp_email)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling SMTPApi->send_transac_email: %s\n" % e)

我有一个示例脚本工作:

我成功收到了电子邮件和 messageId 作为回复。

如果有帮助,请告诉我!

于 2020-08-24T18:22:53.973 回答