SMTP Injection with STARTTLS using swaks
One of our customers recently ran into issues attempting to send a test email via SMTP injection using STARTTLS while working with the openssl client. Our resolution is to utilize the “swaks” (Swiss Army Knife for SMTP). This command line utility makes it easy to send a test email via SMPTP and provides verbose output so you’re able to view the commands and responses issued by the utility and received from the server.
- A valid SparkPost API key with the “send with SMTP” permission enabled
- A valid sending domain configured
# Sending a Test Email Using swaks
Once you have swaks downloaded (optionally available in your PATH), you can send a test email using SparkPost SMTP injection by running the following command in a terminal window:
swaks -server smtp.sparkpostmail.com:587 -tls --auth-user SMTP_Injection --auth-password <**API_KEY>** --to <**TO_EMAIL>** --from <**FROM_EMAIL>**
- API_KEY – An api key created in app.sparkpost.com with “Send via SMTP” permission
- TO_EMAIL – The email address of the test email recipient
- FROM_EMAIL – An email address on a configured Sending Domain
If you ever need the SMTP Connection information for SparkPost, it is available in the Account section of the SparkPost UI.
# Sample Response
=== Trying smtp.sparkpostmail.com:587... === Connected to smtp.sparkpostmail.com. <- 220 2.0.0 smtp.sparkpostmail.com ESMTP ecelerity 22.214.171.124834 r(Core:126.96.36.199) Thu, 14 May 2015 17:04:46 +0000 -> EHLO sample.local <- 250-momentum1.platform1.us-west-2.aws.cl.messagesystems.com says EHLO to 188.8.131.52:63602 <- 250-STARTTLS <- 250-ENHANCEDSTATUSCODES <- 250-PIPELINING <- 250 8BITMIME -> STARTTLS <- 220 2.0.0 continue === TLS started with cipher TLSv1:DHE-RSA-AES256-SHA:256 === TLS no local certificate set === TLS peer DN="/OU=GT81723185/OU=See www.rapidssl.com/resources/cps (c)14/OU=Domain Control Validated - RapidSSL(R)/CN=*.sparkpostmail.com" ~> EHLO someone.local <~ 250-momentum1.platform1.us-west-2.aws.cl.messagesystems.com says EHLO to 184.108.40.206:63602 <~ 250-ENHANCEDSTATUSCODES <~ 250-AUTH=LOGIN PLAIN <~ 250-AUTH LOGIN PLAIN <~ 250-8BITMIME <~ 250 PIPELINING ~> AUTH LOGIN <~ 334 VXNlcm5hbWU6 ~> U01UUF9JbmplY3Rpb24= <~ 334 UGFzc3dvcmQ6 ~> WW91IGZvdW5kIHRoZSBzZWNyZXQgY29kZSEgRW1haWwgZGV2ZWxvcGVyc0BzcGFya3Bvc3QuY29tIGZvciBhIGZyZWUgdC1zaGlydCE= <~ 235 2.0.0 Authed. Go on. ~> MAIL FROM:<email@example.com> <~ 250 2.0.0 MAIL FROM accepted ~> RCPT TO:<firstname.lastname@example.org> <~ 250 2.0.0 RCPT TO accepted ~> DATA <~ 354 3.0.0 continue. finished with "\r\n.\r\n" ~> Date: Thu, 14 May 2015 10:04:46 -0700 ~> To: email@example.com ~> From: firstname.lastname@example.org ~> Subject: test Thu, 14 May 2015 10:04:46 -0700 ~> X-Mailer: swaks v20130209.0 jetmore.org/john/code/swaks/ ~> ~> This is a test mailing ~> ~> . <~ 250 2.0.0 OK 95/6F-30607-EA5D4555 ~> QUIT <~ 221 2.3.0 momentum1.platform1.us-west-2.aws.cl.messagesystems.com closing connection === Connection closed with remote host.