-
Notifications
You must be signed in to change notification settings - Fork 0
3. The sendmail() Function
Vismaya Atreya edited this page Aug 11, 2020
·
2 revisions
Now that we created the window for the user to write the email, something should happen in the background too, when you send the email. We will have to define another function. I call this one sendmail()
def sendmail():
try:
context = ssl.create_default_context()
with smtplib.SMTP(smtp_server, port) as server:
server.ehlo()
server.starttls(context=context)
server.ehlo()
server.login(sender_email, password)
message = message_box.get('1.0', 'end-1c')
receiver_email = receiver_email_entry.get().split(' ')
server.sendmail(sender_email, receiver_email, ('Subject: ' + subject_box.get() + '\n' + message) + '\n \nSent with Python smtplib and ssl modules (Project at: https://github.com/VismayaAtreya/Send-Emails-Python)' )
except Exception as e:
showinfo('Error while sending', e)