如何将邮件直接发送到SMTP服务器而无需身份验证? [英] How to send a mail directly to SMTP server without authentication?

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

问题描述

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



但是,我不希望在脚本中使用gmail密码。从我读到的内容来看,Gmail似乎需要进行身份验证,然后才能发送任何邮件,包括向其自己的用户发送邮件。



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

  import smtplib 
导入电子邮件
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:
失败= server.sendmail(user@gmail.com,user@gmail.com,msg.as_string())
server.close()
,例外情况如e:
print(e)

运行此脚本时,输出为:

 (530,b'5.5.1需要身份验证。请参阅
了解详情5.5.1 http://support.google.com /mail/bin/answer.py?answer=14257 fw5sm21125889wib.0','user@gmail.com')

我的问题是,外部SMTP服务器如何避免此问题?是否它们在本地脚本中可以复制,还是需要正确的反向DNS记录,SPF记录等?

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



这些SMTP服务器还必须具有正确的反向区域ISP的DNS,否则这个smtp将被谷歌封锁。


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

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.

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')

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.?

解决方案

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.

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天全站免登陆