こんにちは松田です。
telnetコマンドを使ってGmail宛にメールを送信してみます。
各バージョン
- CentOS 7.4
- telnet 0.17-64
GmailのメールサーバのFQDNを調べる
MXレコードを引いてGmailのメールサーバ(SMTPサーバ)を調べます。
1
2
3
4
5
6
|
[root@srv ~]# dig gmail.com mx +short
10 alt1.gmail-smtp-in.l.google.com.
20 alt2.gmail-smtp-in.l.google.com.
30 alt3.gmail-smtp-in.l.google.com.
40 alt4.gmail-smtp-in.l.google.com.
5 gmail-smtp-in.l.google.com.
|
5つ出てきました。どれでも良いのですが、
今回はalt1.gmail-smtp-in.l.google.com.を使おうと思います。
telnetでSMTP通信
以下のようにtelnetコマンドでメールサーバ(SMTPサーバ)に接続します。
telnet [FQDN] [ポート番号]
1
2
3
4
|
[root@srv ~]# telnet alt1.gmail-smtp-in.l.google.com. 25
Trying 64.233.179.27...
Connected to alt1.gmail-smtp-in.l.google.com..
Escape character is '^]'.
|
接続できたらSMTPのコマンドを使ってメールを送ります。
コマンドは以下の流れになります。
1
2
3
4
5
6
|
EHLO [自分のドメイン]
MAIL FROM: [自分のメールアドレス]
RCPT TO: [宛先メールアドレス]
DATA
[タイトルや本文などを入力。'.'のみの行が終わりを示す]
QUIT
|
実際に送ってみます。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
[root@srv ~]# telnet alt1.gmail-smtp-in.l.google.com. 25
Trying 64.233.179.27...
Connected to alt1.gmail-smtp-in.l.google.com..
Escape character is '^]'.
220 mx.google.com ESMTP e36si5284762otb.323 - gsmtp
HELO example.com
250 mx.google.com at your service
MAIL FROM: <test@example.com>
250 2.1.0 OK e36si5284762otb.323 - gsmtp
RCPT TO: <xxxxx@gmail.com(※自分のGmailアドレス)>
250 2.1.5 OK e36si5284762otb.323 - gsmtp
DATA
354Go ahead e36si5284762otb.323 - gsmtp
Subject: test
Hello,
This is test mail.
.
421-4.7.0 [xxx.xxx.xxx.xxx 15] Our system has detected that this message is
421-4.7.0 suspicious due to the very low reputation of the sending IP address.
421-4.7.0 To protect our users from spam, mail sent from your IP address has
421-4.7.0 been temporarily rate limited. Please visit
421 4.7.0https://support.google.com/mail/answer/188131 for more information. e36si5284762otb.323 - gsmtp
Connection closed by foreign host.
|
SMTPの処理としては正常に受け付けてくれましたが、
Gmailのスパムメール対策により拒否されてしまいました。
SPFレコードでスパムメールでないことを証明
メール送信元アドレスのドメインにSPFレコードを登録してスパムメールではないことを証明します。 (※もちろん自分のドメインが必要になります)
今回は以下のTXTレコードを登録しました。
1
|
"v=spf1 ip4:【telnetを行うサーバのIPアドレス】 -all"
|
再度telnetを試行
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
[root@srv ~]# telnet alt1.gmail-smtp-in.l.google.com. 25
Trying 108.177.8.26...
Connected to alt1.gmail-smtp-in.l.google.com..
Escape character is '^]'.
220 mx.google.com ESMTP b77kg9274928tst.204 - gsmtp
HELO 【自分のドメイン】
250 mx.google.com at your service
MAIL FROM: <test@【自分のドメイン】>
250 2.1.0 OK b77kg9274928tst.204 - gsmtp
RCPT TO: <xxxxx@gmail.com(※自分のGMailアドレス)>
250 2.1.5 OK b77kg9274928tst.204 - gsmtp
DATA
354Go ahead b77kg9274928tst.204 - gsmtp
From: <test@【自分のドメイン】>
Subject: test
Hello,
This is test mail.
.
250 2.0.0 OK1568373717 b77kg9274928tst.204 - gsmtp
QUIT
221 2.0.0 closing connection b77kg9274928tst.204 - gsmtp
Connection closed by foreign host.
|
今度はGmail側で拒否されずにメール送信が成功しました!
また自分のGmailにメールが届いたことも確認できました!
終わり
無事にtelnetでGmail宛にメールを送信することができました。
この記事が誰かのお役に立てば幸いです。