Cómo utilizar SWAKS con SparkPost

Cómo utilizar SWAKS con SparkPost

Cómo utilizar SWAKS con SparkPost

Jun 24, 2021

Publicado por

Publicado por

Bird

Bird

-

Categoría:

Categoría:

Email

Email

Ready to see Bird
in action?

Ready to see Bird
in action?

How to Use SWAKS with SparkPost

El año pasado publicamos un artículo en nuestro blog que mostraba cómo utilizar la omnipresente y muy útil herramienta telnet para comprobar una conexión SMTP.

En 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 opciones 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 este 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 preajustes all your defaults parameters. This makes running SWAKS literally a button (OK, “key”) away! 

Para el propósito de este ejercicio, vamos a ejecutar los comandos desde un servidor CentOS 7 pero los comandos son similares en todas las plataformas soportadas. Como se mencionó anteriormente, si estás atascado, sólo tienes que copiar y pegar directamente en tu sistema y modificar lo que necesites. Aquí están los conceptos básicos:


Instale

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

Una vez instalado, ésta es la sintaxis básica para enviar un mensaje. En este ejemplo, estamos utilizando la dirección local del servidor:

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

Envía un mensaje con un encabezado de línea "Asunto" + otros encabezados y luego incluye un texto "¡Hola Mundo!" en el cuerpo:

swaks -s 127.0.0.1 -f me@from.com -t them@recipient.com --header "Asunto: ¡Hola! Este es el encabezado del asuntoSegundo_encabezado:123\nTercer_encabezado:XYZ" --body "¡Hola Mundo!"

A continuación se muestra cómo añadir un archivo adjunto, donde SWAKS realiza la conversión base64 por usted, ideal para probar los límites de tamaño de los mensajes:

swaks -s 127.0.0.1 -f me@from.com -t them@recipient.com --attach /ruta/a/archivo.tgz

Ya tienes lo básico. Ahora vamos a ver cómo puedes mejorar tu configuración. Aquí tienes algunas ideas:

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

  • Medir la latencia al conectar y cerrar una conexión a un servidor de correo.

  • Probar diferentes versiones de TLS y cifrados

Aquí no te vas a quedar solo, te voy a enseñar cómo hacer todo lo anterior. Esta vez vamos a inyectar en nuestros servidores SparkPost.


Send a message to our SparkPost servers (How to cree la clave API aquí, 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 [su clave auth] -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 todas las versiones anteriores de TLS excepto v1.2 y superiores. 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

En este ejemplo, estamos utilizando "tlsv1_2", pero adelante, cámbielo por "tlsv1_1" y utilícelo en otros dominios para observar su compatibilidad.

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


Como prometí, si has llegado hasta aquí la recompensa es así de sencilla canta un archivo de configuración para establecer los parámetros por defecto:


$ 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

Una vez que lo hayas guardado, escribe "swaks", lo rellenará todo y lo enviará a su destino. Y lo que es mejor, puedes anularlo añadiéndolo en la línea de comandos, por ejemplo, si quieres un destinatario diferente:


swaks -t recipient@somewherelse.com

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

En right message -> a la right person -> en el right time.

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

The right message -> a la right person -> en el right time.