使用' SendInBlue'发送交易和营销电子邮件

时间:2016-09-09 07:47:58

标签: python transactional-email sendinblue

我想使用' 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密钥。

1 个答案:

答案 0 :(得分:0)

我强烈建议您使用latest版的SendinBlue的Python包装器,因为他们提供了example

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作为响应。

请帮助我!