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

2024-05-15 16:20:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用苹果邮件应用程序和protonmail-我有桥接应用程序。(MacOS and Windows install herelinux here。)

激活网桥应用程序后,我试图使用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:事务失败,归咎于天气:MIME头行格式错误:00')


Tags: installand苹果com应用程序hereserverwindows
1条回答
网友
1楼 · 发布于 2024-05-15 16:20:56

这可能会有帮助。。在

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()

相关问题 更多 >