kotlin 发送短信_在kotlin中使用sendinblue发送交易电子邮件

kotlin 发送短信

In this tutorial, we are going to explain how to send transactional emails with Sendinblue.

在本教程中,我们将解释如何使用Sendinblue发送交易电子邮件。

“Sendinblue is a comprehensive suite of SaaS communication tools, including email marketing, transactional emails, text messages, and more.” — Sendinblue’s official documentation

“Sendinblue是SaaS的通讯工具,包括电子邮件营销,交易电子邮件,短信,以及全面的套件更多 。” — Sendinblue的官方文档

Sendinblue’s transactional email documentation recommends the use of their API clients, which are available and documented in: C#, Go, Java, Node JS, PHP, Python, and Ruby. What about Kotlin?

Sendinblue的事务性电子邮件文档建议使用其API客户端 ,这些客户端在以下版本中可用并进行了记录: C#GoJavaNode JSPHPPythonRuby 。 那Kotlin呢?

First of all, we need to understand what a transactional email is.

首先,我们需要了解什么是交易电子邮件。

“A transactional email is an email that is automatically sent by your website to a single recipient resulting from a transaction or a specific event performed by that person, such as an eCommerce purchase or a password reset request.” — The Complete Marketer’s Guide to Transactional Emails

“一个 交易电子邮件 是由您的网站自动发送给单个收件人的电子邮件,该电子邮件是由该人执行的交易或特定事件(例如电子商务购买或密码重置请求)产生的。” — 交易电子邮件的完整营销人员指南

Now we are ready to dive into the tutorial.

现在我们准备好学习本教程。

创建一个新的Sendinblue帐户 (Creating a New Sendinblue Account)

Before anything else, we need an account with Sendinblue. Several plans are available, but we will use the free one, which comes with some limitations, as described in Is there a limit to the free plan?

首先,我们需要拥有Sendinblue的帐户。 有几种可用的计划 ,但是我们将使用免费计划 ,它有一些限制,如免费计划有限制吗?

You can create a new account on this page: https://app.sendinblue.com/account/register

您可以在此页面上创建一个新帐户: https : //app.sendinblue.com/account/register

When you’ve done that, it’s time to get our Sendinblue API key, which is necessary to start calling Sendinblue API. You can retrieve your API key as described in the documentation under Get your API key.

完成之后,是时候获取我们的Sendinblue API密钥了 ,这是开始调用Sendinblue API所必需的。 您可以按照获取API密钥下的文档中所述检索API密钥

Now, we can start writing some lines of code.

现在,我们可以开始编写一些代码行。

安装Sendinblue API客户端 (Installing the Sendinblue API Client)

In order to send transactional emails in Kotlin, we need to install the Sendinblue API client.

为了在Kotlin中发送交易电子邮件,我们需要安装Sendinblue API客户端

If you are a Gradle user, add this dependency to your project’s build file:

如果您是Gradle用户,请将此依赖项添加到项目的构建文件中:

compile "com.sendinblue:sib-api-v3-sdk:4.1.1"

Otherwise, if you are a Maven user, add the following dependency to your project’s build POM:

否则,如果您是Maven用户,则将以下依赖项添加到项目的构建POM中:

<dependency>
<groupId>com.sendinblue</groupId>
<artifactId>sib-api-v3-sdk</artifactId>
<version>4.1.1</version>
<scope>compile</scope>
</dependency>

The Sendinblue API client is now installed and ready to be used.

现在已安装Sendinblue API客户端并可以使用。

定义包含动态内容的新模板 (Defining a New Template Including Dynamic Content)

Sendinblue allows users to define their own custom templates for designing emails. Templates support dynamic content, which can be filled with contact attributes (by default, a contact comes with the following attributes: EMAIL, FIRSTNAME, LASTNAME, SMS), predefined variables, and custom-defined transactional parameters.

Sendinblue允许用户定义自己的自定义模板来设计电子邮件。 模板支持动态内容,其中可以填充联系人属性 (默认情况下,联系人具有以下属性: EMAILFIRSTNAMELASTNAMESMS ), 预定义变量和自定义事务参数

The goal of this tutorial is not to show how to define a template in Sendinblue. So, to complete this step, following the official guide is highly recommended.

本教程的目的不是显示如何在Sendinblue中定义模板。 因此,为完成此步骤,强烈建议您遵循官方指南。

Please note: Do not forget to save the ID of the template you just created since we are going to use it in the next step.

请注意:不要忘记保存刚刚创建的模板的ID,因为我们将在下一步中使用它。

Now we have all the required building blocks to send our first transactional email in Kotlin. Let’s see how in the next step.

现在,我们拥有在Kotlin中发送第一封交易电子邮件所需的所有构造块。 让我们看看下一步。

发送交易电子邮件 (Sending a Transactional Email)

Time to see how can we send a transactional email in Kotlin. This can be easily achieved with the following lines of code:

是时候看看我们如何在Kotlin中发送交易电子邮件了。 使用以下代码行可以轻松实现:

Transactional parameters must be defined in a Map<String,String> object. A Map is a collection that holds pairs of <key,value> objects. In each pair, the key is the name of a parameter as defined in the template, and the value is the corresponding value we want to give to the selected parameter.

事务参数必须在Map <String,String>对象中定义。 映射是包含成对的<key,value>对象的集合。 在每对中, key是模板中定义的参数的名称,而value是我们要赋予所选参数的相应值。

The Sendinblue API client requires a list of SendSmtpEmailTo objects, each of which represents one recipient.

Sendinblue API客户端需要一个SendSmtpEmailTo对象列表,每个对象代表一个收件人。

Each recipient must have an email, while a name is optional. The former should be a contact registered in Sendinblue and assigned to a contact list, and the latter is the name that will be attached to the email recipient, which will appear in the email headers, but not in the email body.

每个收件人都必须有一封电子邮件,而名称是可选的。 前者应该是在Sendinblue中注册并分配给联系人列表的联系人,而后者是将附加到电子邮件收件人的名称,该名称将出现在电子邮件标题中,而不出现在电子邮件正文中。

If you created a template as described in the previous step, this is the result you should get:

如果按照上一步中的描述创建了模板,则应得到以下结果:

Image for post

额外 (Extra)

We have just seen how to send a transactional email with the official Sendinblue API client, but the same result can be achieved using the POST https://api.sendinblue.com/v3/smtp/email API.

我们刚刚看到了如何使用官方的Sendinblue API客户端发送事务性电子邮件,但是使用POST https://api.sendinblue.com/v3/smtp/email API可以实现相同的结果。

结论 (Conclusion)

In this tutorial, we showed how to send transactional emails in Kotlin. We managed to achieve our goal by harnessing the official Sendinblue Java API client and taking advantage of Kotlin’s peculiar feature of being interoperable with Java.

在本教程中,我们展示了如何在Kotlin中发送交易电子邮件。 我们通过利用官方的Sendinblue Java API客户端并利用Kotlin与Java互操作的独特功能,成功实现了我们的目标。

I hope that you found this article helpful — thanks for reading! Let me know if you have any comments or suggestions.

我希望您认为这篇文章对您有所帮助-感谢您的阅读! 如果您有任何意见或建议,请告诉我。

翻译自: https://medium.com/better-programming/sending-transactional-emails-with-sendinblue-in-kotlin-6f6920f49733

kotlin 发送短信

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值