smtp.gmail.com vs ssl://smtp.gmail.com使用Gmail邮件服务器发送电子邮件 [英] smtp.gmail.com vs ssl://smtp.gmail.com while sending email using gmail smtp server

查看:287
本文介绍了smtp.gmail.com vs ssl://smtp.gmail.com使用Gmail邮件服务器发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据


Gmail SMTP服务器也可用于转发来自
设备或应用程序的邮件。您可以使用
SMTP,SSL / TLS连接到Gmail邮件服务器。如果您使用SMTP连接,则只能将邮件发送到
Gmail或Google Apps用户;如果您使用SSL / TLS连接,则可以将
邮件发送给任何人。



如果您的设备或应用程序支持SSL,请连接到smtp.gmail.com $

所以我尝试连接到端口465上的smtp.gmail.com。我得到以下错误:


无法使用PHP SMTP发送电子邮件。您的服务器可能不是
配置为使用此方法发送邮件。


某些代码使用另一个地址ssl://smtp.gmail.com。



当我使用ssl: //smtp.gmail.com也在端口465上,我的应用程序现在可以正常工作。




  • ssl:// smtp有什么区别。 gmail.com和smtp.gmail.com,如果后者也使用ssl?

  • 为什么我们无法将电子邮件发送到没有SSL的其他域?这只是由gmail出于安全目的完成的吗?



我对此非常新颖。谁能解释一下?

解决方案

主机名前缀与 ssl:/ / ,没有它是基础流是否包装 a>通过OpenSSL,或以纯文本方式发言。



当您通过端口465连接到Gmail时,它预计客户端将使用TLS加密。很可能,您看到的错误消息是连接到期望加密连接的服务的一般结果,因为它只是试图以纯文本格式编写和读取数据。



当您使用 ssl:// 封装器连接到支持TLS或SSL的服务时,PHP对您来说很神奇。它允许你读取和写入数据流(使用fread / fwrite),就像你使用未加密的连接一样,所有的握手,加密和解密都是在背景中完成的,但不得超过主机前缀与ssl包装。



至于第二个问题,它最有可能是安全相关的。为了中继(将邮件发送到另一个域),您需要通过SMTP进行身份验证,而不应以明文方式进行身份验证,而您可以使用未加密的连接在端口25上进行连接,并在未进行身份验证的情况下将邮件发送给Gmail用户(这是最常见的当他们的用户之一将邮件发送到Gmail时,邮件服务器会执行此操作)。但从技术上讲,没有什么能阻止他们使用未加密的连接发送邮件,甚至无法使用Gmail凭据进行身份验证(这称为开放式转发,通常被垃圾邮件发送者滥用)。

通过阅读SMTP协议, STARTTLS 命令以及一般TLS加密,您可以了解有关第一个问题的更多信息。 STARTTLS 允许客户端通过未加密的连接连接到邮件服务器,然后协商(升级)连接以使用加密,另一方面,端口465的连接期望一旦建立连接并且发生任何协议(SMTP)通信之前,就会发生TLS握手。

According to this

Gmail SMTP Server could also be used to relay messages from your device or application. You can connect to Gmail mail servers using SMTP, SSL/TLS. If you connect using SMTP, you can only send mail to Gmail or Google Apps users; if you connect using SSL/TLS, you can send mail to anyone.

If your device or application supports SSL - connect to smtp.gmail.com on port 465.

So I tried connecting to smtp.gmail.com on port 465. I got the following error:

Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

Some code uses another address "ssl://smtp.gmail.com".

When I use ssl://smtp.gmail.com also on port 465, my application now works correctly.

  • What's the difference between ssl://smtp.gmail.com and smtp.gmail.com if the latter also uses ssl?
  • Why can't we send emails to other domains without SSL? Is this only done by gmail for security purposes?

I am extremely new at this. Can anyone explain? I am using php if it matters.

解决方案

The difference between the prefixing the hostname with ssl:// and without it is whether or not the underlying stream will be wrapped through OpenSSL, or speak in plain text.

When you connect to Gmail on port 465, it expects the client will use TLS encryption. Most likely, the error message you were seeing was a general result of connecting to a service expecting an encrypted connection when it was just trying to write and read data in plain text.

PHP does magic for you when you use the ssl:// wrapper to connect to a service that supports TLS or SSL. It allows you to read and write on the stream (using say fread/fwrite) in the same manner you would on an unencrypted connection and all the handshaking, encryption, and decryption is done in the background having to do no more than prefix the host with the ssl wrapper.

As to the second question, it is most likely security related. In order to relay (send mail to another domain) you need to authenticate over SMTP which should NEVER be done in cleartext while you can connect on port 25 using an unencrypted connection and send mail to a Gmail user without authenticating (this is what most outside mail servers do when one of their users which to send mail to Gmail). But technologically, there's nothing preventing them from allowing you to send mail using an unencrypted connection, or even authenticating with Gmail credentials (this is called an open relay and is usually badly abused by spammers).

You can learn more about your first question by just reading about the SMTP protocol, the STARTTLS command, and TLS encryption in general. STARTTLS allows a client to connect to the mail server over an unencrypted connection and then negotiate (upgrade) the connection to use encryption, where on the other hand, connections to port 465 expect a TLS handshake to occur as soon as the connection is established and before any protocol (SMTP) communication occurs.

这篇关于smtp.gmail.com vs ssl://smtp.gmail.com使用Gmail邮件服务器发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆