我正在使用带有 protonmail 的苹果邮件应用程序——我有 bridge 应用程序。 (MacOS and Windows install here;linux here。)
激活 bridge 应用程序后,我尝试使用 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()
我收到的错误信息:
smtplib.SMTPDataError: (554, b'Error: transaction failed, blame it to the weather: malformed MIME header line: 00')
最佳答案
这可能会有所帮助..
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()
关于python - 从 Protonmail 帐户、SMTP 库使用 Python 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56330521/