-1

I have problem with sending email from console. When i run my script, it stucks in the first command, and next commands not executing. What can i do?

#!/bin/bash

openssl s_client -starttls smtp -crlf  -connect smtp.gmail.com:587
auth plain
(((((here is my login:pass))))
mail from: <test@gmail.com>
rcpt to: <test2@gmail.com>
data

my mail 
.

quit
  • [How to debug a bash script?](https://unix.stackexchange.com/q/155551/56041) (U&L.SE), [How to debug a bash script?](https://stackoverflow.com/q/951336/608639) (SO), [How to debug bash script?](https://askubuntu.com/q/21136) (AskU), [Debugging Bash scripts](http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html), etc. – jww Mar 24 '18 at 18:18
  • `openssl (options) << EOF end put an EOF below your stdin for openssl. Also look at `expect` which may be more suitable for this task. – Ljm Dullaart Mar 24 '18 at 22:27

1 Answers1

-1

The first command is a shell command, the rest should be input to that command, but you've written them as a part of the shell script. What you're trying to do could be done with a here-document:

openssl s_client ... <<EOF
auth plain
...
EOF

However, trying to send email using openssl s_client? You're gonna' have a bad time. You're probably not going to get this to work at all. Use an MTA or (maybe even better) an MUA/MSA. If you need a lightweight MTA try esmtp-run. Then you can set up your username/password in esmtprc (or any other MTA/MDA configuration). If you feel the need to do this close to the metal:

/usr/sbin/sendmail -ti <<EOF
To: myself@gmail.com
From: myself@gmail.com
Subject: Test email
Date: Fri, 23 Mar 2018 22:26:38 0000 (GMT)

This is a test...

-- 
Myself
EOF
Morten
  • 634
  • 5
  • 13