smtplib无法连接到

2024-09-29 22:30:56 发布

您现在位置:Python中文网/ 问答频道 /正文

因此,我尝试使用smtplib库使用"smtp.gmail.com"主机发送电子邮件。这是我的密码:

#!/usr/bin/python3

import smtplib
from getpass import getpass

class NoReceivers(Exception):
    """Exception raised when there are no receivers."""
    pass

sender = # EMAIL ADRESS
print(f"Account used: {sender}")
password = getpass("\nEnter password: ")
server = smtplib.SMTP("smtp.gmail.com", 587)
print("\nConnecting to gmail.com...")

try:
    server.starttls()
    server.login(sender, password)
    receivers = input("\nEnter e-mail adresses: ")
    receivers = receivers.split(",")
    if not receivers: raise NoReceivers
    content = input("\nEnter content: ")
    server.sendmail(sender, receivers, content)
except NoReceivers:
    print("\nError: no receivers input!")
except smtplib.SMTPAuthenticationError:
    print("\nError while authentificating! Please retry!")
except smtplib.SMTPRecipientsRefused:
    print("\nReceivers' adresses not found or forbidden!")
except:
    print("\nAn unexpected error occured! Please retry later!")
finally:
    try: server.quit()
    except: pass

但是smtplib.SMTPAuthenticationError总是被提升。有人能帮我吗?你知道吗


Tags: cominputserverpasswordcontentsmtpgmailsender

热门问题