Python smtplib:Gmail 有效,但仅“有时"

2023-07-03Python开发问题
2

本文介绍了Python smtplib:Gmail 有效,但仅“有时"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我编写了一个简单的脚本来通过 Gmail SMTP 服务器发送电子邮件.代码如下:

I wrote a simple script to send an email via the Gmail SMTP server. Here the code:

import smtplib
msg = 'Hello World!'
server = smtplib.SMTP('smtp.gmail.com', 587) #port 465 or 587
server.ehlo()
server.starttls()
server.ehlo()
server.login('username@googlemail.com','password')
server.sendmail('username@googlemail.com','username@googlemail.com', msg)
server.close()

有时它有效,有时我得到一个错误.原因是什么?我已将 Gmail 配置为接受不太安全的应用程序.如果发生错误,我会收到以下消息:

Sometimes it works and sometimes I get an error. What is the reason for it? I have configured Gmail for accepting less secure apps. If the error occurs I get the following message:

Traceback (most recent call last):
  File "email.py", line 31, in <module>
    server.login('username@googlemail.com','password')
  File "/usr/lib/python3.5/smtplib.py", line 729, in login
    raise last_exception
  File "/usr/lib/python3.5/smtplib.py", line 720, in login
    initial_response_ok=initial_response_ok)
  File "/usr/lib/python3.5/smtplib.py", line 641, in auth
    raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (534, b'5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbvQ
5.7.14 DBMYWMukfjghdjfkghfjkhjkfhgjkdhgdfjkghekjghekjgndjkSm5lAOfEpP2Nt
5.7.14 QihtNp5izjfghjjkjhgbhjbGHJVHJVjhvhjbhjbhjDZwhJFV-FiyvI-OGW
5.7.14 jcpmHcQAcOR8e8G0zOfdugjhfdjd-sdfiugdsjfdsrthdfewrzjhg-shgv2HxmgWpZg3Z
5.7.14 4G1ENiAlgiEnrkXyRbTG3frjZZdPg> Please log in via your web browser and
5.7.14 then try again.
5.7.14  Learn more at
5.7.14  https://support.google.com/mail/answer/78754 g40sm24698383wrg.19 - gsmtp')

我在互联网上找不到任何帮助.非常感谢您的每一个建议.

I couldn't find any help on the internet. Many thanks in advance for every advice.

推荐答案

答案建议首先为不太安全的应用启用访问权限.如果这不起作用,您可以尝试访问该页面上提供的链接:https://www.google.com/accounts/DisplayUnlockCaptcha

The answer recommends enabling access for less secure apps first. If that does not work you could try visiting the link, which is supplied on that page: https://www.google.com/accounts/DisplayUnlockCaptcha

这可能会启用访问权限.

This may enable access.

这篇关于Python smtplib:Gmail 有效,但仅“有时"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

在xarray中按单个维度的多个坐标分组
groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)...
2024-08-22 Python开发问题
15

Pandas中的GROUP BY AND SUM不丢失列
Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)...
2024-08-22 Python开发问题
17

pandas 有从特定日期开始的按月分组的方式吗?
Is there a way of group by month in Pandas starting at specific day number?( pandas 有从特定日期开始的按月分组的方式吗?)...
2024-08-22 Python开发问题
10

GROUP BY+新列+基于条件的前一行抓取值
Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)...
2024-08-22 Python开发问题
18

PANDA中的Groupby算法和插值算法
Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)...
2024-08-22 Python开发问题
11

PANAS-基于列对行进行分组,并将NaN替换为非空值
Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)...
2024-08-22 Python开发问题
10