python - 从 Protonmail 帐户、SMTP 库使用 Python 发送电子邮件

标签 python email smtplib mime-mail

我正在使用带有 protonmail 的苹果邮件应用程序——我有 bridge 应用程序。 (MacOS and Windows install herelinux 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/

相关文章:

spring-boot - 将 Springboot 应用程序隔离为电子邮件应用程序的 DEV 环境和 PROD 环境

python-3.7 - smtplib.SMTPNotSupportedError : SMTP AUTH extension not supported by server

python - 等效于 Python OpenCv 的 MATLAB imshow(I,[ ]);

php - 如何在不发送电子邮件的情况下检查电子邮件地址是否存在?

email - GCP错误报告-通知所有者的电子邮件

Python try/except 问题与 SMTPLib

linux - 编译 libsmtp 时出错(找不到 glib-config)

python - 如何生成遗漏 10% 数据的索引集

python - argparse.ArgumentParser 因缺少所需参数而引发什么类型的错误

python - Numpy 字符串编码