如何在没有身份验证的情况下将邮件直接发送到 SMTP 服务器? [英] How to send a mail directly to SMTP server without authentication?

查看:63
本文介绍了如何在没有身份验证的情况下将邮件直接发送到 SMTP 服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过直接连接到 smtp.gmail.com,将电子邮件直接从脚本发送到 Gmail 电子邮件帐户.

I would like to send an email directly from a script to a Gmail email account, by connecting directly to smtp.gmail.com.

但是,我不希望脚本中包含 gmail 密码.从我所读到的内容来看,Gmail 似乎需要身份验证才能发送任何邮件,包括发送给它自己的用户.

However, I would prefer not to have the gmail password in the script. From what I have read, it appears that Gmail requires authentication before it will deliver any mail, including to its own users.

我的问题是,来自另一台 SMTP 服务器的邮件是如何传送的,因为该 SMTP 服务器没有 Gmail 凭据.Gmail 是否只要求对匿名"发件人进行身份验证,并且由于我的脚本在个人计算机上运行,​​因此需要更高的安全性?这是我正在运行的 python 脚本:

My question is, how is mail coming from another SMTP server ever delivered, since that SMTP server will not have Gmail credentials. Does Gmail only require authentication for "anonymous" senders, and since my script is running on a personal computer, it is subject to higher security? Here is the python script I am running:

import smtplib
import email
msg = email.message.Message()
msg["From"] = "user@gmail.com"
msg["To"] = "user@gmail.com"
msg["Subject"] = "Test message"
server = smtplib.SMTP("smtp.gmail.com",587)
server.starttls()
server.ehlo_or_helo_if_needed()
try:
    failed = server.sendmail("user@gmail.com","user@gmail.com", msg.as_string())
    server.close()
except Exception as e:
    print(e)

当我运行这个脚本时,输出是:

When I run this script, the output is:

(530, b'5.5.1 Authentication Required. Learn more at
5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 fw5sm21125889wib.0', 'user@gmail.com')

我的问题是,外部 SMTP 服务器如何避免这个问题?他们所做的一切是否可以在本地脚本中复制,或者是否需要正确的反向 DNS 记录、SPF 记录等?

My question is, how do external SMTP servers avoid this problem? And is whatever they do replicable in a local script, or does it require correct reverse DNS records, SPF records, etc.?

推荐答案

您可以使用一些无需身份验证的外部 SMTP 服务器(或本地 SMTP),但是发送的邮件将被 Google 的垃圾邮件过滤器捕获,因为 msg["From"]@google.com,而实际的 SMTP 不是 smtp.gmail.com.

You can use some external SMTP servers without authentication (or a local SMTP), but the sent message will be caught by Google's spam filter because the msg["From"] is @google.com, while the actual SMTP is not smtp.gmail.com.

那些 SMTP 服务器也必须在 ISP 的 DNS 中有正确的反向区域,否则这个 smtp 将被谷歌阻止.

Those SMTP servers also must have correct reverse zone in ISP's DNS and otherwise this smtp will be blocked by google.

这篇关于如何在没有身份验证的情况下将邮件直接发送到 SMTP 服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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