3 ms·
I used to use it for sending test emails via smtp when troubleshooting other clients struggling to send
by applied_heat 3y ago
I used to use it for sending test emails via smtp when troubleshooting other clients struggling to send
- chasil 3y agoNetcat is really a cleaner solution from this perspective. Netcat, combined with the openssl utility, can do some amazing things with moving files over SMTP. I can post my favorite hand-rolled script if there is interest. I boiled it out of mpack down to the shell.
- pmontra 3y agoPlease, post it or post an URL to the script.
- chasil 3y agoHere is the script. This is like FTP/scp to an inbox. Remove the two leading spaces that HN needs in quoting code blocks. This uses OpenSSL to a) send a base64-encoded MD5 hash of each file in the headers, then b) base64-encode the file itself. There is also an OpenSSL "smime" applet, but I really don't know what it does. The netcat is going to send this over cleartext; use OpenSSL s_client (or maybe "nc -ssl" if your netcat supports it) if cleartext is a problem. This is written in dash, so it should run in most POSIX-compliant shells. Note that local variables are not POSIX-compliant; for a true POSIX shell, change the shell function to "mimer () ( ...body ...)" to force a subshell. Shellcheck doesn't like printf formats done like this, but you can't please everybody. This also works in Windows with ports of OpenSSL and busybox, btw. $ cat mimer #!/bin/dash mimer () { local f \ SMTP='smtp.yourco.com' \ BOUND="$(openssl rand -base64 21 | sed 's@[/+=]@_@g')" \ SFORMAT='helo %s mail from:%s rcpt to:%s data Mime-Version: 1.0 Subject: %s Content-Type: multipart/mixed; boundary="%s" This is a MIME encoded message. ' \ MFORMAT='%s Content-Type: application/octet-stream; name="%s" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="%s" Content-MD5: %s ' { printf "$SFORMAT" "$HOSTNAME" "$2" "$1" "$3" "$BOUND" shift 3 while [ -n "$1" ] do f=${1##*/} printf "$MFORMAT" "--$BOUND" "$f" "$f" \ "$(openssl dgst -md5 -binary < "$1" | openssl base64)" # base64 < "$1" openssl base64 -in "$1" echo shift done printf '%s--\n.\nquit\n' "--$BOUND" } | sed -e 's/$/\r/' | nc "$SMTP" 25 } [ -z "$4" ] && { echo mimer to from subject file1 '[file2]' ...; exit; } mimer "$@"
- hddqsb 3y agoNice, thanks for sharing. Not directly related, but since you mentioned s_client, please see my warning regarding its security: https://news.ycombinator.com/item?id=36179850#36186559 https://news.ycombinator.com/item?id=36179850#36186559
- fragmede 3y agoOver SMTP? I'm interested!
- chasil 3y agoI hope that you like it!
- yjftsjthsd-h 3y ago> Netcat, combined with the openssl utility At that point, wouldn't it be easier to just use socat?
- Melkman 3y agoSocat doesn't support STARTTLS. If you want to debug SMTP submission "openssl s_client -starttls smtp -connect server:587" is awesome. Just take care not to use upper case "R" or "Q". Man, why did they implement rekeying and quit in such a bothersome way. Just use recipient and quit instead of RECIPIENT and QUIT.
- jwilk 3y agoSince OpenSSL 1.1.0, you can turn it off with -nocommands: https://github.com/openssl/openssl/commit/6ba8a5b77af5792b https://github.com/openssl/openssl/commit/6ba8a5b77af5792b
- hddqsb 3y agoSee my warning regarding s_client and security: https://news.ycombinator.com/item?id=36179850#36186559 https://news.ycombinator.com/item?id=36179850#36186559
- hinkley 3y agoLong, long ago in a galaxy far, far away, I used it to debug browser parsing issues. Curl has been around for ages, but not for the entire WWW age.