I want to add subject to my python email program how can i do that? i dont want to use any python libraries i just want to do that with ssl, Can anyone can give me code example so that i can just copy paste? i looked 4 stack over flow solutions too but i dont understand how to do that in my program the reason was i am not a python programmer but i want to use this program, i think to add a subject you hardly have to spend 1 min writing that, to if you know how to do that in ssl only pls answer this question with a code example, dont suggest me any other stack overflow question link because i looked many and i cant able to do that,
import smtplib, ssl
email = "[email protected]"
password = "mypassword"
message = """\
Hello World
"""
receiver = "[email protected]"
port = 465
sslcontext = ssl.create_default_context()
connection = smtplib.SMTP_SSL("smtp.gmail.com", port, context=sslcontext)
connection.login(email, password)
connection.sendmail(email, reciever, message)
print("sent")
CodePudding user response:
You can make the subject as a header of the body text.
Try this :
import smtplib, ssl
email = "[email protected]"
password = "mypassword"
subject= "Put here your subject"
body = """\
Hello World
"""
message = 'Subject: {}\n\n{}'.format(subject, body)
receiver = "[email protected]"
port = 465
sslcontext = ssl.create_default_context()
connection = smtplib.SMTP_SSL("smtp.gmail.com", port, context=sslcontext)
connection.login(email, password)
connection.sendmail(email, reciever, message)
print("sent")