-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemailing.py
31 lines (25 loc) · 969 Bytes
/
emailing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def email_function(email_input, message_text):
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from tkinter import messagebox
gmailUser = '[email protected]'
gmailPassword = 'xxxxxxx'
recipient = '[email protected]'
message = message_text
msg = MIMEMultipart()
msg['From'] = f'"Your Name" <{gmailUser}>'
msg['To'] = recipient
msg['Subject'] = "Subject here..."
msg.attach(MIMEText(message))
try:
mailServer = smtplib.SMTP('smtp.gmail.com', 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(gmailUser, gmailPassword)
mailServer.sendmail(gmailUser, recipient, msg.as_string())
mailServer.quit()
messagebox.showinfo('Email','Information hasn been sentto ' + email_input)
except:
messagebox.showerror('Error','Cannot send email to ' + email_input)