Hoe gebruik je SWAKS met SparkPost?

Hoe gebruik je SWAKS met SparkPost?

Hoe gebruik je SWAKS met SparkPost?

Jun 24, 2021

Gepubliceerd door

Gepubliceerd door

Bird

Bird

-

Categorie:

Categorie:

E-mail

E-mail

Ready to see Bird
in action?

Ready to see Bird
in action?

How to Use SWAKS with SparkPost

Vorig jaar hebben we een blogartikel gepubliceerd dat laat zien hoe u het alomtegenwoordige en zeer nuttige telnet-hulpmiddel kunt gebruiken om een SMTP-verbinding te controleren.

De 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 opties 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 deze 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 pre-sets all your defaults parameters. This makes running SWAKS literally a button (OK, “key”) away! 

Voor deze oefening gaan we de commando's uitvoeren vanaf een CentOS 7 server, maar de commando's zijn vergelijkbaar op alle ondersteunde platformen. Zoals hierboven vermeld, als u vastzit, kopieert en plakt u gewoon rechtstreeks in uw systeem en wijzigt u wat u nodig hebt. Dit is de basis:


Installeer

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

Eenmaal geïnstalleerd is hier de basissyntaxis om een bericht te versturen. In dit voorbeeld gebruiken we het lokale adres van de server:

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

Stuur een bericht met een "Subject" regel header + andere headers en dan een "Hello World!" tekst in de body:

swaks -s 127.0.0.1 -f me@from.com -t them@recipient.com --header "Subject: Hallo! Dit is het onderwerp headerSecond_header:123Third_Header:XYZ" --body "Hello World!"

Hier ziet u hoe u een bijlage toevoegt, waarbij SWAKS de base64-conversie voor u doet, geweldig voor het testen van berichtgroottelimieten:

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

De basis is zo goed als klaar! Laten we eens kijken hoe je nog meer kunt doen. Hier zijn enkele ideeën:

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

  • Meet de latentie bij het verbinden en sluiten van een verbinding met een mailserver.

  • Verschillende TLS-versies en cijfers testen

Je wordt hier niet alleen gelaten, ik zal je laten zien hoe je dit allemaal moet doen. Deze keer gaan we injecteren in onze SparkPost servers.


Send a message to our SparkPost servers (How to maak hier de API sleutel aan, 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 [uw auth-sleutel] -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 alle oudere TLS-versies behalve v1.2 en hoger. 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

In dit voorbeeld gebruiken we "tlsv1_2", maar ga je gang en verander dat in "tlsv1_1" en gebruik het op andere domeinen om hun compatibiliteit te observeren.

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


Zoals beloofd, als je het zo ver hebt geschopt, is de beloning deze eenvoudige zing een configuratiebestand om standaardparameters in te stellen:


$ 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

Zodra u het opslaat, typt u gewoon "swaks" en het vult alles vooraf in en stuurt het op zijn vrolijke manier! Nog beter, u kunt het overschrijven door het toe te voegen op de opdrachtregel, bijvoorbeeld als u een andere ontvanger wilt:


swaks -t recipient@somewherelse.com

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

De right message -> naar de right person -> aan de right time.

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

The right message -> naar de right person -> aan de right time.