从 Protonmail 帐户、SMTP 库发送带有 Python 的电子邮件

Sending an email with Python from a Protonmail account, SMTP library

我正在使用 Apple 邮件应用,protonmail-I 有桥接应用。 (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()

我对此很陌生,遇到了一些重大问题....直到我做了以下微小的改变:

将 from 行更改为:

import smtplib 
from email.mime.multipart import MIMEMultipart
from email.mime.text 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()