Cara Menggunakan SWAKS dengan SparkPost

Cara Menggunakan SWAKS dengan SparkPost

Cara Menggunakan SWAKS dengan SparkPost

Jun 24, 2021

Diterbitkan oleh

Diterbitkan oleh

Bird

Bird

Kategori:

Kategori:

Email

Email

Ready to see Bird
in action?

Ready to see Bird
in action?

How to Use SWAKS with SparkPost

Tahun lalu, kami menerbitkan artikel blog yang menunjukkan cara menggunakan alat telnet yang ada di mana-mana dan sangat berguna untuk memeriksa koneksi SMTP.

The 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 pilihan 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 ini 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 pra-setel all your defaults parameters. This makes running SWAKS literally a button (OK, “key”) away! 

Untuk tujuan latihan ini, kita akan menjalankan perintah-perintah dari server CentOS 7, tetapi perintah-perintahnya serupa pada semua platform yang didukung. Seperti disebutkan di atas, jika Anda mengalami kebuntuan, salin dan tempelkan saja langsung ke dalam sistem Anda dan modifikasi apa yang Anda perlukan. Inilah dasar-dasarnya:


Memasang

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

Setelah terinstal, berikut adalah sintaks dasar untuk mengirim pesan. Dalam contoh ini, kami menggunakan alamat lokal server:

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

Kirim pesan dengan tajuk baris "Subjek" + tajuk lainnya, lalu sertakan teks "Halo Dunia!" di badan pesan:

swaks -s 127.0.0.1 -f me@from.com -t them@recipient.com --header "Subject: Halo! Ini adalah tajuk subjek\Tajuk_kedua:123\nTajuk_ketiga:XYZ" --body "Halo Dunia!"

Berikut ini cara menambahkan lampiran, di mana SWAKS melakukan konversi base64 untuk Anda, sangat bagus untuk menguji batas ukuran pesan:

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

Anda sudah cukup menguasai dasar-dasarnya! Sekarang, mari kita lihat, bagaimana Anda bisa meningkatkan permainan pengaturan Anda. Berikut adalah beberapa ide:

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

  • Mengukur latensi saat menghubungkan dan menutup koneksi ke server email.

  • Menguji berbagai versi TLS dan sandi yang berbeda

Anda tidak akan ditinggalkan sendirian di sini, saya akan menunjukkan kepada Anda bagaimana melakukan semua hal di atas. Kali ini kita akan menyuntikkan ke dalam server SparkPost.


Send a message to our SparkPost servers (How to buat kunci API di sini, 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-pengguna SMTP_Injection -auth-password [kunci auth Anda] -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 semua versi TLS yang lebih lama kecuali v1.2 dan yang lebih baru. 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

Dalam contoh ini, kita menggunakan "tlsv1_2" tetapi silakan ubah menjadi "tlsv1_1" dan gunakan pada domain lain untuk mengamati kompatibilitasnya.

What if you want to waktu 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


Seperti yang dijanjikan, jika Anda berhasil sampai sejauh ini, hadiahnya sesederhana menyanyikan file konfigurasi untuk mengatur parameter default:


$ 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

Setelah Anda menyimpannya, cukup ketik "swaks" dan aplikasi ini akan mengisi ulang semuanya dan mengirimkannya dengan senang hati! Lebih baik lagi, Anda bisa mengganti dengan menambahkannya pada baris perintah, misalnya Anda menginginkan penerima yang berbeda:


swaks -t recipient@somewherelse.com

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

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

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

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