📜  gmail smtp telnet (1)

📅  最后修改于: 2023-12-03 15:30:59.145000             🧑  作者: Mango

Gmail SMTP Telnet

Introduction

SMTP (Simple Mail Transfer Protocol) is a protocol used for sending email messages between servers. Telnet is a way of connecting to a server via the command line. In combination, telnet can be used to connect to an SMTP server and send email messages manually.

In this tutorial, we will use telnet to connect to Gmail's SMTP server and send an email message through it. We will assume that you have some basic knowledge of the command line and SMTP.

Prerequisites

To follow along with this tutorial, you will need the following:

  • A Gmail account
  • Access to a command line interface (Terminal on Mac or Command Prompt on Windows)
  • Telnet installed on your computer (this should be a default feature on most operating systems)
Steps
1. Enable Less Secure App Access

Gmail security settings by default do not allow less secure apps to access your account. Since we will be connecting to the SMTP server via telnet, we will need to enable less secure app access in your Gmail account. To do this:

  1. Log in to your Gmail account
  2. Go to https://myaccount.google.com/
  3. Click on Security on the left-hand side
  4. Under Less secure app access, turn on Allow less secure apps
2. Connect to SMTP Server

Next, we will use telnet to connect to the Gmail SMTP server on port 587. Open up your command line interface and enter the following command:

telnet smtp.gmail.com 587

You should see some output that looks like this:

Trying 74.125.195.109...
Connected to gmail-smtp-msa.l.google.com.
Escape character is '^]'.
220 smtp.gmail.com ESMTP w27sm2757712wmd.27 - gsmtp
3. Initiate Secure Connection

Once you have successfully connected to the SMTP server, we need to initiate a secure connection by running the following command:

STARTTLS

You will receive a response that looks like this:

220 2.0.0 Ready to start TLS
4. Authenticate with Your Gmail Account

After initiating a secure connection, we need to authenticate ourselves with our Gmail account. Enter the following command:

AUTH LOGIN

You will receive a response that looks like this:

334 VXNlcm5hbWU6

This is a Base64 encoded string that expects your email address. Enter your email address in Base64 format, then press enter. You will receive a response that looks like this:

334 UGFzc3dvcmQ6

This is another Base64 encoded string that expects your Gmail account password. Enter your password in Base64 format, then press enter. You will receive a response that looks like this:

235 2.7.0 Accepted

This indicates that you have successfully authenticated with the Gmail SMTP server.

5. Set Email Sender

After authentication, we need to set the email sender address. Run the following command:

MAIL FROM: <your-email-address>

Replace <your-email-address> with your actual email address. You will receive a response that looks like this:

250 2.1.0 OK w27sm2757712wmd.27 - gsmtp
6. Set Recipient Email Address

Next, we need to set the recipient email address. Run the following command:

RCPT TO: <recipient-email-address>

Replace <recipient-email-address> with the email address of the recipient. You will receive a response that looks like this:

250 2.1.5 OK w27sm2757712wmd.27 - gsmtp
7. Set Email Message

After setting the recipient email address, we can now set the email message. Run the following command:

DATA

You will receive a response that looks like this:

354  Go ahead w27sm2757712wmd.27 - gsmtp

This means that the server is ready to receive the email message. Enter the following text and press enter:

Subject: Test Email

This is a test email message sent via telnet.
.

Note that there is a period at the end of the message, which indicates the end of the message.

You will receive a response that looks like this:

250 2.0.0 OK  1598975509 w27sm2757712wmd.27 - gsmtp

This means that the email message has been sent successfully.

8. Quit Telnet

After sending the email message, we can quit telnet by running the following command:

QUIT

You will receive a response that looks like this:

221 2.0.0 closing connection w27sm2757712wmd.27 - gsmtp

This means that the connection has been closed successfully.

Conclusion

In this tutorial, we learned how to use telnet to send an email message through Gmail's SMTP server. Although this is not a practical way of sending email messages, it can be a helpful tool for troubleshooting SMTP-related issues.