通过命令行连接到 smtp.gmail.com
我正在编写一个通过有效的 GMail 用户 ID 和密码发送邮件的应用程序。
我只是想在 Windows XP 命令行上模拟 SMTP 连接,当我在 465 端口 telnet smtp.gmail.com
时,我看不到任何东西。将打开一个标题为 Telnet smtp.gmail.com
并带有光标的空白命令窗口。当我输入 EHLO
或通常的 SMTP 握手命令时,提示符就会关闭。
我无法弄清楚出了什么问题以及出在哪里。我尝试连接到 587,它根本无法在 telnet 中连接。如果我做错了什么,有人可以澄清吗?
I am in the process of writing an application that sends mail via an valid GMail user ID and password.
I just wanted to simulate the SMTP connection on my Windows XP command line, and when I telnet smtp.gmail.com
at 465 port - I don't see any thing. A blank command window with title Telnet smtp.gmail.com
opens with cursor. When I type in EHLO
or usual SMTP handshake commands, the prompt just closes.
I am unable to figure out whats going wrong and where. I tried connecting to 587, it does not connect in telnet at all. Could anyone please clarify if I am doing something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
使用 Linux 或 OSx,按照 Sorin 的建议进行操作,但使用端口 465。 25 是通用 SMTP 端口,但不是 GMail 使用的端口。另外,我不相信您想使用 -starttls smtp
您应该获得有关 SSL 会话和响应的大量信息:
输入
,您将收到:
从那里它并不像发送 SMTP 消息那么简单,因为Gmail 具有适当的保护措施,可确保您仅发送看似来自实际属于您的帐户的电子邮件。不要输入“Helo”,而使用“Ehlo”。我对 SMTP 不太了解,所以我无法解释其中的区别,也没有时间进行太多研究。也许有更多知识的人可以解释一下。
然后,输入“auth login”,您将收到以下内容:
这本质上是在 Base 64 中编码的单词“用户名”。使用 Base 64 编码器,例如 这个,对您的用户名进行编码并输入。对接下来要求的密码执行相同的操作。您应该看到:
就这样,您已经登录了。
如果您使用 OSx 或 Linux 终端,还需要克服一个奇怪的问题。仅按“ENTER”键显然不会导致 SMTP 需要结束邮件所需的 CRLF。您必须使用“CTRL+V+ENTER”。因此,这应该如下所示:
Using Linux or OSx, do what Sorin recommended but use port 465 instead. 25 is the generic SMTP port, but not what GMail uses. Also, I don't believe you want to use -starttls smtp
You should get lots of information on the SSL session and the response:
Type in
and you'll receive:
From there it is not quite as straightforward as just sending SMTP messages because Gmail has protections in place to ensure you only send emails appearing to be from accounts that actually belong to you. Instead of typing in "Helo", use "Ehlo". I don't know much about SMTP so I cannot explain the difference, and don't have time to research much. Perhaps someone with more knowledge can explain.
Then, type "auth login" and you will receive the following:
This is essentially the word "Username" encoded in Base 64. Using a Base 64 encoder such as this one, encode your user name and enter it. Do the same for your password, which is requested next. You should see:
And that's it, you're logged in.
There is one more oddity to overcome if you're using OSx or Linux terminals. Just pressing the "ENTER" key does not apparently result in a CRLF which SMTP needs to end a message. You have to use "CTRL+V+ENTER". So, this should look like the following:
从终端启动会话:
openssl s_client -connect smtp.gmail.com:25 -starttls smtp
响应的最后一行应为“250 SMTPUTF8”
启动登录
身份验证登录
这应该返回“334 VXNlcm5hbWU6”。
输入用户名
以base64编码输入您的用户名(例如
echo -n 'your-username' | base64
)这应该返回“334 UGFzc3dvcmQ6”
输入密码
以 base64 编码输入您的密码(例如
echo -n 'your-password' | base64
)成功
您应该看到“235 2.7.0 Accepted”并且您'已成功登录
Start session from terminal:
openssl s_client -connect smtp.gmail.com:25 -starttls smtp
The last line of the response should be "250 SMTPUTF8"
Initiate login
auth login
This should return "334 VXNlcm5hbWU6".
Type username
Type your username in base64 encoding (eg.
echo -n 'your-username' | base64
)This should return "334 UGFzc3dvcmQ6"
Type password
Type your password in base64 encoding (eg.
echo -n 'your-password' | base64
)Success
You should see "235 2.7.0 Accepted" and you're are successfully logged in
对于 OSX 终端:
For OSX' terminal:
Gmail 要求与其服务器之间的 SMTP 通信进行加密。尽管您在端口 465 上打开了与 Gmail 服务器的连接,但遗憾的是,您将无法以明文方式与其进行通信,因为 Gmail 要求您对连接使用 STARTTLS/SSL 加密。
Gmail require SMTP communication with their server to be encrypted. Although you're opening up a connection to Gmail's server on port 465, unfortunately you won't be able to communicate with it in plaintext as Gmail require you to use STARTTLS/SSL encryption for the connection.
Jadaaih,您可以通过 CURL 连接发送 SMTP - Curl 开发者社区链接。
这是Curl 电子邮件客户端源。
Jadaaih, you can connect send SMTP through CURL - link to Curl Developer Community.
This is Curl Email Client source.
试试这个:
Try this:
检查 lifehacker 中的这篇文章: Geek to Live:使用 fetchmail 备份 Gmail。它使用命令行程序。检查一下是否有帮助。顺便说一句,当有许多其他不错的选择时,为什么还要使用命令行?
Check this post in lifehacker : Geek to Live: Back up Gmail with fetchmail . It uses a command line program. Check and see if it helps. BTW why are you using command line when there are many other nice alternatives?
tcp/465 最初旨在首先建立 SSL(和较新的 TLS)层,并在内部执行明文或普通旧协议(此处为 smtp)
tcp/587 最初旨在作为垃圾邮件发送者和群发邮件时默认 tcp/25 端口的替代品攻击开始于十年或更久以前,但也在那些臭名昭著的 AOL 时代,当时一些有趣的 ISP 对默认出站端口(例如 tcp/25)进行了一些阻止,以拒绝自己的客户 (AOL) 批量发送电子邮件/当时的垃圾邮件,但需要使用替代邮件帐户和邮件提供商的 AOL 客户仍然需要从 AOL 互联网连接发送邮件,因此他们仍然可以连接到 tcp/587 并在当时执行简单的 smtp。
处理 STARTTLS 方式进行 smtp 的方法是使用两个众所周知的原始明文 tcp/25 和 tcp/587 端口,并且只有当初始明文连接成功时,才启动 TLS 层(因此 STARTTLS)从那时起,就拥有了安全的连接。
至于调试这类事情,可以通过命令行工具进行,例如,对于 Windows,有历史上的 blat 命令行邮件程序(smtp),到目前为止它还不能执行 TLS(STARTTLS),因此它只能使用纯文本 smtp 来发送邮件。
http://www.blat.net/
然后有许多具有更多功能的免费软件和开源软件项目和功能,例如
smtp 客户端:mailsend @ googlecode
http://code.google.com/p/mailsend/
smtp 客户端:msmtp @ sourceforge (与下面的mpop相关)
http://msmtp.sourceforge.net/
pop3 客户端:mpop @ sourceforge
http://mpop.sourceforge.net/
tcp/465 was initially intended for establishing the SSL(and newer TLS) layer first, and inside doing cleartext or plain old protocols (smtp here)
tcp/587 was intended as a replacement to default tcp/25 port initially when spammers and mass mailing attacks commenced like a decade or more ago, but also during those infamous AOL ages, when some funny ISP had some blocks on default ports outbound (such as that tcp/25) for denying their own customers (AOL) to mass-send emails/spam back then, but AOL-customers needing to use alternative mail-accounts and mail-providers still needed to send their mails from AOL-internet connections, so they could still connect to tcp/587 and do simple smtp on it back then.
The deal with the STARTTLS way to do smtp is to use the two well known originally plain-text tcp/25 and tcp/587 ports, and only when the initial clear-text connect suceeded, to then START the TLS layer (thus STARTTLS) from there on, having a secured connection from that point onwards.
As for debugging these kind of things maybe via command-line tools, for example for windows there is the historical blat command line mailer (smtp), which up till today cant do TLS (STARTTLS) so it can only use plain-text smtp to send its mails.
http://www.blat.net/
Then there are numerous projects freeware and open source software that have more capabilities and features, such as
smtp client: mailsend @ googlecode
http://code.google.com/p/mailsend/
smtp client: msmtp @ sourceforge (related to mpop below)
http://msmtp.sourceforge.net/
pop3 client: mpop @ sourceforge
http://mpop.sourceforge.net/
如何从命令行连接到“Google SMTP邮件服务器”?
1] SSL 连接命令,
带变量
smtp.gmail.com
587
echo -n '{{user_name }}' | base64
echo -n '{{user_password}}' | base64
2] SMTP 邮件服务器命令 - 每个命令都在一行中
How to connect to "Google SMTP mail server" from the command line?
1] SSL connect command
with variables
smtp.gmail.com
587
echo -n '{{user_name}}' | base64
echo -n '{{user_password}}' | base64
2] SMTP mail server commands - every command in one line
Gmail 使用加密连接。因此,即使建立连接后,您也无法发送任何电子邮件。加密管理起来有点复杂。尝试使用 openssl 代替。
下面的线程应该有所帮助 -
如何使用简单的发送电子邮件通过 Gmail 执行 SMTP 命令?
gmail uses an encrypted connection. So, even after you establish a connection, you wont be able to send any email. The encryption is a little complex to manage. Try using openssl instead.
The thread below should help-
How to send email using simple SMTP commands via Gmail?