使用 Python 从 Protonmail 帐户、SMTP 库发送电子邮件

sem*_*ena 10 python email smtplib mime-mail

我正在使用带有质子邮件的苹果邮件应用程序 - 我有桥接应用程序。(此处安装 MacOS 和 Windows此处安装linux。)

激活桥接应用程序后,我尝试使用 smtp 库用 python 发送电子邮件,但它不起作用。这是我尝试运行但失败的代码:

import smtplib

server = smtplib.SMTP("127.0.0.1", portnumber)
server.login("mymail@protonmail.com", "my password")
server.sendmail(
    "mymail@protonmail.com",
    "receiver@protonmail.com",
    "hello")
server.quit()
Run Code Online (Sandbox Code Playgroud)

我收到的错误消息:

smtplib.SMTPDataError: (554, b'Error: 交易失败,归咎于天气:格式错误的 MIME 标题行:00')

Tec*_*ion 8

这可能有帮助..

import smtplib 
from email.MIMEMultipart import MIMEMultipart 
from email.MIMEText import MIMEText

port_number =1234
msg = MIMEMultipart()
msg['From'] = 'sender@protonmail.com'
msg['To'] = 'receiver@protonmail.com'
msg['Subject'] = 'My Test Mail '
message = 'This is the body of the mail'
msg.attach(MIMEText(message))
mailserver = smtplib.SMTP('localhost',port_number)
mailserver.login("sender@protonmail.com", "mypassword")
mailserver.sendmail('sender@protonmail.com','receiver@protonmail.com',msg.as_string())
mailserver.quit()
Run Code Online (Sandbox Code Playgroud)

  • 需要注意的是,只有当您在运行此脚本的计算机上运行 protonmail 桥接软件时,这才有效。您不能简单地在 `mailserver.login()` 行输入您的帐户密码;您必须检查桥应用程序是否有为您的帐户提供的散列(或伪?)密码。 (3认同)