Send email using OpenSSL
15,586
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
Related videos on Youtube
Author by
3bdalla
Updated on September 18, 2022Comments
-
3bdalla over 1 year
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.
-
wurtel over 8 yearsMany 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.
-
Edward Falk over 7 yearsPerhaps expect(1) will do what you want?
-
-
s3lph over 8 yearsI was just about to answer something like this...
-
Арсений Черенков over 8 yearstry to add -pause option ? (after -crlf but before <<EOF
-
Alessio over 8 yearsDon't forget to insert a blank line between the last header (
Subject:
in this case) and the first line of the body. -
Yaroslav Nikitenko over 7 yearsI'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.
-
tripleee almost 7 yearsYou should use double quotes around every string which doesn't specifically require wildcard expansion and whitespace tokenization. In particular, the password might well contain shell metacharacters.
-
Dmitry Grigoryev almost 5 yearsCould you make it a standalone answer? "The script as above" doesn't make sense as answers can be added, removed and voted on.