Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save huynhbaoan/64c38368d19bca79a7007541b780a07c to your computer and use it in GitHub Desktop.
Save huynhbaoan/64c38368d19bca79a7007541b780a07c to your computer and use it in GitHub Desktop.
#!/bin/bash
# === Configuration ===
SMTP_SERVER="smtp.example.com"
SMTP_PORT="25" # Use 25 for no encryption. Use 587/465 only with TLS support (see note below)
EHLO_DOMAIN="myhost.example.com"
MAIL_FROM="[email protected]"
RCPT_TO="[email protected]"
SUBJECT="Netcat Test Email"
BODY="Hello,\r\n\r\nThis is a test email sent using netcat from a Bash script.\r\n\r\nRegards,\r\nNetcat Tester"
# === SMTP Conversation ===
{
printf "EHLO $EHLO_DOMAIN\r\n"
sleep 1
printf "MAIL FROM:<$MAIL_FROM>\r\n"
sleep 1
printf "RCPT TO:<$RCPT_TO>\r\n"
sleep 1
printf "DATA\r\n"
sleep 1
printf "Subject: $SUBJECT\r\n"
printf "To: <$RCPT_TO>\r\n"
printf "From: <$MAIL_FROM>\r\n"
printf "\r\n"
printf "$BODY\r\n"
printf ".\r\n"
sleep 1
printf "QUIT\r\n"
} | nc "$SMTP_SERVER" "$SMTP_PORT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment