2 ms·
Please, post it or post an URL to the script.
by pmontra 3y ago
Please, 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