12

I am using apple mail app with protonmail-I have the bridge app. (MacOS and Windows install here; linux here.)

After activating the bridge app, I tried to send an email with python by using smtp library and it does not work. Here is the code which I tried to run and failed me:

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

The error message I receive:

smtplib.SMTPDataError: (554, b'Error: transaction failed, blame it on the weather: malformed MIME header line: 00')

4

2 回答 2

10

This might help..

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()
于 2019-05-27T18:34:39.457 回答
2

I'm pretty new to this and was having some significant trouble.... until I just made the following tiny change:

Change the from lines to this:

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()
于 2020-09-14T14:17:52.240 回答