How to send mail using telnet command in linux

To send an email using the telnet command in Linux, you'll need to follow these steps:

Prerequisites:

  1. You have a working email server (e.g., Gmail, Outlook, or a self-hosted mail server).
  2. You have the telnet command installed on your Linux system.

Step-by-Step Instructions:

  1. Open a terminal on your Linux system.

  2. Use the telnet command to connect to your email server's SMTP port (usually port 25). For example, if you're using Gmail, you can use the following command:

    telnet smtp.gmail.com 25

    Replace smtp.gmail.com with your email server's hostname or IP address.

  3. Once connected, you'll see a response from the email server. This response should include the SMTP server's greeting and a prompt to enter commands.

  4. To send an email, you'll need to issue a series of SMTP commands. Here's an example of the commands you'll need to send a simple email:

    HELO [email protected]
    MAIL FROM: [email protected]
    RCPT TO: [email protected]
    DATA
    Subject: Your email subject
    Your email body
    .
    QUIT

    Here's a breakdown of each command:

  1. Press Enter after each command to execute it. You'll see a response from the email server indicating the success or failure of each command.
  2. Once you've entered all the commands, press Enter again to disconnect from the SMTP server.

Example:

Here's an example of sending an email using the telnet command:

$ telnet smtp.gmail.com 25
Trying 74.125.24.108...
Connected to smtp.gmail.com.
Escape character is '^]'.
220 mx.google.com ESMTP p10sm1041139wjb.14 - gsmtp
HELO [email protected]
250 mx.google.com at your service, [[email protected]]
MAIL FROM: [email protected]
250 2.1.0 Address accepted
RCPT TO: [email protected]
250 2.1.5 Address accepted
DATA
354 Go ahead and send the message
Subject: Test email from telnet
This is a test email sent using telnet.
.
250 2.0.0 Message accepted for delivery
QUIT
221 2.0.0 closing connection
Connection closed.

Note: This is a basic example, and you may need to modify the commands or add additional headers depending on your specific email server configuration. Additionally, be aware that using telnet to send emails can be insecure, as it doesn't encrypt the email transmission.