Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending an email with Python from a Protonmail account, SMTP library

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("[email protected]", "my password")
server.sendmail(
    "[email protected]",
    "[email protected]",
    "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')

like image 502
semchena Avatar asked May 27 '19 17:05

semchena


1 Answers

This might help..

import smtplib 
from email.MIMEMultipart import MIMEMultipart 
from email.MIMEText import MIMEText

port_number =1234
msg = MIMEMultipart()
msg['From'] = '[email protected]'
msg['To'] = '[email protected]'
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("[email protected]", "mypassword")
mailserver.sendmail('[email protected]','[email protected]',msg.as_string())
mailserver.quit()
like image 138
Tech at The Sparks Foundation Avatar answered Sep 17 '22 23:09

Tech at The Sparks Foundation