Sending Email (TLS) using Command Line

There are times when we need to check whether we can send email using specific mail server from command line. In this example, we are going to send email using a mail server on secure connection (port 465 or 587). The text in bold is the one we need type. We need to change the one with underline on it.

To use SSL/TLS on port 465:

$ openssl s_client -crlf -quiet -connect smtp.server.com:465

To use STARTTLS on port 587:

$ openssl s_client -crlf -quiet -starttls smtp -connect smtp.server.com:587

depth=2 C = US, O = “VeriSign, Inc.”, OU = VeriSign Trust Network, OU = “(c) 2006 VeriSign, Inc. – For authorized use only”, CN = VeriSign Class 3 Public Primary Certification Authority – G5
verify return:1
depth=1 C = US, O = Symantec Corporation, OU = Symantec Trust Network, CN = Symantec Class 3 Secure Server CA – G4
verify return:1
depth=0 C = US, ST = Washington, L = Seattle, O = “smtp.com, Inc.”, CN = smtp.server.com
verify return:1
220 smtp.server.com ESMTP EmailService-1737464811 q9foEapZyGpqLYwMbkii
EHLO domain-name.com
250-email-smtp-server.com
250-8BITMIME
250-SIZE 10485760
250-AUTH PLAIN LOGIN
250 Ok
AUTH LOGIN
334 VXNlcm5hbWU6
YourBase64UsernameHere
334 UGFzc3dvcmQ6
YourBase64PasswordHere
235 Authentication successful.
MAIL FROM:sender@email.com
250 Ok
RCPT TO:recipient@email.com
250 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
Subject: Testing Email

This email was sent using command line.
.
250 Ok 01000158d8d607b6-c9ec22ef-4ca3-4e03-9fac-b1340d485950-000000
quit
221 Bye

 

To convert text to base64 for username and password, you can use the following command:

$ echo -n ‘YourTextHere‘ | base64

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s