如何在SparkPost中使用SWAKS?

如何在SparkPost中使用SWAKS?

如何在SparkPost中使用SWAKS?

Jun 24, 2021

出版商

出版商

Bird

Bird

-

类别

类别

电子邮件

电子邮件

Ready to see Bird
in action?

Ready to see Bird
in action?

How to Use SWAKS with SparkPost

去年,我们发表了一篇博客文章,介绍了如何使用无处不在、非常有用的telnet工具来检查SMTP连接。

ǞǞǞ next step is to simplify the manual process by using an awesome “next level” tool (it refers to itself as the Swiss Army Knife of email) called SWAKS. This is a command line tool that can send emails via SMTP. It’s not only easy to use but also simultaneously provides a myriad of 选项 when needed.

At first, I was intimidated by the amount of options, but it is perfectly usable with the most basic options. If you have any issues, just bookmark 这个 page, copy and paste the examples, and modify it to your liking. At the end of this blog, once you have gained some familiarity and don’t have a lot of variance/dynamics to your SWAKS commands, I will show you how to create a configuration file that 预设 all your defaults parameters. This makes running SWAKS literally a button (OK, “key”) away! 

为了这个练习的目的,我们将在CentOS 7服务器上运行这些命令,但这些命令在所有支持的平台上都是类似的。如上所述,如果你被卡住了,就直接复制和粘贴到你的系统中,然后修改你需要的内容。下面是基本的内容。


安装

sudo yum install epel-release -y && sudo yum install swaks -y

一旦安装完毕,下面是发送消息的基本语法。在这个例子中,我们使用的是服务器的本地地址。

swaks -s 127.0.0.1 -f sender@from.com -t recipient@recipient.com

发送一条带有 "主题 "行标题+其他标题的信息,然后在正文中包含一个 "Hello World!"的文本。

swaks -s 127.0.0.1 -f me@from.com -t them@recipient.com --header "Subject:Hello!This is the subject header\Second_header:123\nThird_Header:XYZ" --body "Hello World!"

下面是添加附件的方法,SWAKS为你做base64转换,非常适合测试邮件大小的限制。

swaks -s 127.0.0.1 -f me@from.com -t them@recipient.com --attach /path/to/file.tgz

你已经基本掌握了基础知识!现在,让我们看看你还可以如何提高你的设置游戏。这里有一些想法。

  • Use a scheduler like chron to do basic ‘does it work’ tests which can work as a foundation  or even augment your monitoring system.

  • 测量连接和关闭与邮件服务器的连接时的延迟。

  • 测试不同的TLS版本和密码器

在这里,你不会被抛弃,我将向你展示如何完成上述所有工作。这一次我们要注入到我们的SparkPost服务器中。


Send a message to our SparkPost servers (How to 在这里创建API密钥, and the SMTP options).Once you get your authentication key, paste it into the command (make sure to keep the key safe and secure!) :

swaks -server smtp.sparkpostmail.com:587 -tls -auth-user SMTP_Injection -auth-password [your auth key] -f me@from.com -t them@recipient.com

If you’re looking for guidance on how to troubleshoot sending via SMTP to our servers check out this article.

Echoing best security practices, SparkPost has deprecated 除v1.2及以上版本外的所有旧版TLS. If you want to see if your system is compatible, SWAKS allows you to test specific TLS versions and ciphers.

swaks -s smtp.sparkpostmail.com -tls  -p 587 -f me@from.com -t them@recipient.com -tlsp tlsv1_2 --tls-cipher ECDHE-RSA-AES128-GCM-SHA256

在这个例子中,我们使用的是 "tlsv1_2",但请继续将其改为 "tlsv1_1",并在其他域中使用,以观察其兼容性。

What if you want to 时间 how fast a mail server responds? SWAKS can go through the SMTP cycle and disengage at some points without sending a message, and you can time it using the “time” command which shows at end of output:

$ time swaks -s 127.0.0.1 -f sender@from.com -t them@recipient.com test--quit-after RCPT === Trying 127.0.0.1:25... === Connected to 127.0.0.1. …  -> RCPT TO:<them@recipient.com> <-  250 2.1.5 <them@recipient.com> ok  -> QUIT <-  221 2.0.0 v1pmta5.jasdevism.com says goodbye === Connection closed with remote host. real 0m0.049s user 0m0.038s sys 0m0.009s


正如承诺的那样,如果你走到这一步,奖励就是这么简单,唱一个配置文件来设置默认参数。


$ Cd $HOME $ vim .swaksrc  # Copy and paste this into the file into the .swaksrc file --from swakstest@jasdevism.com h-From: "Jas Swaks" <swakstest@jasdevism.com> -s 127.0.0.1  --body "This is a test!" --to jsingh@sparkpost.com

一旦你保存了它,只需输入 "swaks",它就会预先填入所有内容,并把它送上它的快乐之路!更好的是,你可以通过在命令行中添加它来覆盖,比如说你想要一个不同的收件人。


swaks -t recipient@somewherelse.com

Your new standard in Marketing, Pay & Sales. It's Bird

ǞǞǞ right message ->right person ->right time.

Your new standard in Marketing, Pay & Sales. It's Bird

The right message ->right person ->right time.