【问题标题】:Send transactional and marketing emails using 'SendInBlue'使用“SendInBlue”发送交易和营销电子邮件
【发布时间】:2017-01-17 07:13:51
【问题描述】:

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

【问题讨论】:

  • @garg10我可以通过包含代码部分来编辑我的问题。
  • 您要设置哪些详细信息?部分 smtp 设置由get_smtp_details api 调用提供。
  • 先生,您能否给我看一个使用 python 从 SendInBlue 发送活动邮件的示例脚本?

标签: python transactional-email sendinblue


【解决方案1】:

我强烈建议您使用 SendinBlue 的 Python 包装器的 latest 版本,他们提供了 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 作为回复。

如果有帮助请告诉我!

【讨论】:

  • 在最近的版本中,类名SMTPApi已更改为TransactionalEmailsApi,查看the issue
猜你喜欢
  • 2011-05-18
  • 2020-05-31
  • 2021-07-28
  • 2014-05-30
  • 2015-10-13
  • 2014-03-03
  • 1970-01-01
  • 2014-10-11
  • 1970-01-01
相关资源
最近更新 更多