Skip to content

Instantly share code, notes, and snippets.

@boina-n
Last active November 9, 2022 03:58
Show Gist options
  • Save boina-n/e43b996fa0f520c918e3ed6beb754447 to your computer and use it in GitHub Desktop.
Save boina-n/e43b996fa0f520c918e3ed6beb754447 to your computer and use it in GitHub Desktop.
Use telnet to send email with an attachement
#!/bin/bash
filename="/path/to/your/file.log"
subject="Subject of my email"
txtmessage="This is the message I want to send"
{
sleep 1;
echo "EHLO mydomain.intra"
sleep 1;
echo "MAIL FROM:me@example.com"
sleep 1;
echo "RCPT TO:him@example.com"
sleep 1;
echo "DATA"
sleep 1;
echo "Subject:" $subject
sleep 1;
echo "Content-Type: multipart/mixed; boundary="KkK170891tpbkKk__FV_KKKkkkjjwq""
sleep 1;
echo ""
sleep 1;
echo "This is a MIME formatted message. If you see this text it means that your"
sleep 1;
echo "email software does not support MIME formatted messages."
sleep 1;
echo ""
sleep 1;
echo "--KkK170891tpbkKk__FV_KKKkkkjjwq"
sleep 1;
echo "Content-Type: text/plain; charset=UTF-8; format=flowed"
sleep 1;
echo "Content-Disposition: inline"
sleep 1;
echo ""
sleep 1;
echo $txtmessage
sleep 1;
echo ""
sleep 1;
echo ""
sleep 1;
echo "--KkK170891tpbkKk__FV_KKKkkkjjwq"
sleep 1;
echo "Content-Type: file --mime-type -b filename-$(date +%y%m%d).zip; name=filename-$(date +%y%m%d).zip"
sleep 1;
echo "Content-Transfer-Encoding: base64"
sleep 1;
echo "Content-Disposition: attachment; filename="filename-$(date +%y%m%d).zip";"
sleep 1;
echo ""
sleep 1;
# The content is encoded in base64.
cat $filename | base64;
sleep 1;
echo ""
sleep 1;
echo ""
sleep 1;
echo "--KkK170891tpbkKk__FV_KKKkkkjjwq--"
sleep 1;
echo ""
sleep 1;
echo "."
sleep 1;
echo "quit"
} | telnet smtp.server.intra 25
@magicj
Copy link

magicj commented Nov 9, 2022

This was very helpful, just have a question though, how do I send with an attachment size greater than 5MB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment