Keywords: email | console | cmd | smtp | sendmail
Abstract: This article explains how to send emails directly from the Microsoft Command Prompt using SMTP protocols with NSLOOKUP and TELNET, addressing common errors and providing alternative methods with third-party tools.
Introduction
Many users encounter difficulties when attempting to send emails through the Microsoft Command Prompt (CMD) console. Common issues include unrecognized commands or file access errors, as highlighted in the provided question where attempts using sendmail and Outlook failed. This article addresses these challenges by presenting a reliable method for sending emails directly via SMTP using built-in tools like NSLOOKUP and TELNET, based on the accepted answer from the technical community.
Method 1: Direct SMTP Communication via TELNET
This method involves manually interacting with an SMTP server to send emails without relying on third-party software. It is particularly useful for testing and educational purposes.
Step 1: Determine the Mail Server
To send an email, first identify the mail server of the recipient's domain using the NSLOOKUP command. Open a CMD prompt and execute:
NSLOOKUP
set q=mx
theirdomain.com
exitThis returns the MX record, such as mail.theirdomain.com, which indicates the mail exchanger.
Step 2: Connect to the Mail Server
SMTP typically uses port 25. Use the TELNET command to establish a connection:
TELNET MAIL.THEIRDOMAIN.COM 25A successful response might be 220 mx.google.com ESMTP 6si6253627yxg.6. If no response, check firewall settings or server availability.
Step 3: Send an Email
Once connected, use SMTP commands to send a test email. Type the following commands precisely, without using backspace:
ehlo mydomain.com
mail from:<martin9700@mydomain.com>
rcpt to:<recipient@theirdomain.com>
data
This is a test, please do not respond
.
quitExplanation of commands:
- EHLO: Introduces your domain to the server.
- MAIL FROM: Specifies the sender's email address, enclosed in angle brackets.
- RCPT TO: Specifies the recipient's email address.
- DATA: Indicates the start of the email body.
- . (a single period on a line): Ends the data portion.
- quit: Terminates the session.
Step 4: Test SMTP Relay
To test if the server allows relay, change the RCPT TO address to a domain not controlled by the server. If an error occurs, relay is disabled.
Method 2: Alternative Approaches
For users preferring not to interact directly with SMTP, third-party command-line mailers offer convenient alternatives. For example, blat can be used as follows:
blat -to you@example.com -f me@example.net -s "mail subject" ^
-server smtp.example.net -body "message text"Similarly, bmail or custom scripts in VBScript or PowerShell provide flexible solutions for automated email sending from the command line.
Conclusion
Sending emails via the CMD console is feasible through direct SMTP communication using TELNET, which provides insight into email protocols. While this method requires manual steps, it is effective for testing and learning. Alternatively, third-party tools simplify the process for practical applications. By understanding these techniques, users can overcome common issues and leverage the command line for email tasks.