我正在使用带有protonmail的Apple Mail应用程序-我有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()
我收到的错误消息:
斯姆普利布。SMTPData错误:(554,b'错误:事务失败,归咎于天气:格式错误的MIME标头行: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()