Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can i add subject to my python email program in ssl?

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 = "myemail@gmail.com"
password = "mypassword"

message = """\
Hello World
"""

receiver = "reciveremail@gmail.com"
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")

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can make the subject as a header of the body text.

Try this :

import smtplib, ssl

email = "myemail@gmail.com"
password = "mypassword"

subject= "Put here your subject"
body = """\
Hello World
"""
message = 'Subject: {}\n\n{}'.format(subject, body)

receiver = "reciveremail@gmail.com"
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")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading