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')
这可能有帮助..
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)