6

With OpenSSL module under openSUSE I can send an email using this list of commands

openssl s_client -starttls smtp -connect smtp.gmail.com:587 -crlf
helo
auth login
(Put base64 encoded username)
(Put base64 encoded password)
mail from:<email>
rcpt to:<email>
Data
From: email
To: email1, email2, .....
Subject: 
(Message body goes here)
.

Is it possible for such a list of commands to be executed at one shot? For example a script?

Note: There is an embedded-Linux system which contains the OpenSSL module, same thing will be applied to it.

  • 3
    Many mail servers will disconnect if the client sends the next command before the response to the previous command has been given, as that is more often than not what a spam tool will do. – wurtel Oct 19 '15 at 10:04
  • 1
    Perhaps expect(1) will do what you want? – Edward Falk Aug 2 '16 at 22:24
7

have you tried

openssl s_client -starttls smtp -connect smtp.gmail.com:587 -crlf  <<EOF
helo
auth login
$(echo $username | base64)
$(echo $password | base64)
mail from:$email0
rcpt to:$email0
Data
From: $email0
To: $emaildest
Subject: $(echo $subject)

$(< body.txt)
.
EOF
  • you must but message's body in body.txt (and remove after)
  • you must set all $var ...

On a side note, if you sign and encrypt mail, you may wish to look at this question

  • I was just about to answer something like this... – s3lph Oct 18 '15 at 9:06
  • I have set all env vars. It seems like it executes the first line and exits. It only shows the certificate and other related stuff and that's it. No steps shown for any other steps. – 3bdalla Oct 18 '15 at 9:29
  • try to add -pause option ? (after -crlf but before <<EOF – Archemar Oct 18 '15 at 9:41
  • Don't forget to insert a blank line between the last header (Subject: in this case) and the first line of the body. – cas Oct 18 '15 at 11:05
  • I'd like to note that I used this solution, but it didn't work for large attachments (about 4 Mb). I hade to use a python script for that (using smtplib). OpenSSL returned "RENEGOTIATING error in s_client", but fortunately python worked fine. – Yaroslav Nikitenko Sep 23 '16 at 14:19
-3

to 3bdalla: I had to solve a similar problem when the ssl connection was established but no data of application layer was transferred, only certificate was shown. Try to add in the line with openssl command following parameters: -key, keyfile, -cert and certfile after <port> parameter:

openssl s_client -connect <host>:<port> -key <keyfile> -cert <certfile>

(Firstly I tried command: echo "some_data" | openssl s_client -connect <host>:<port> -key <keyfile> -cert <certfile>)

  • 1
    Could you make it a standalone answer? "The script as above" doesn't make sense as answers can be added, removed and voted on. – Dmitry Grigoryev Jun 21 at 8:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.