-
Notifications
You must be signed in to change notification settings - Fork 8
/
myemail.py
67 lines (61 loc) · 2.16 KB
/
myemail.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import console, dialogs
import smtplib
import time
import ui
def send_action(sender):
global sendto, subj, assignment, v
sendto = v['tofield'].text
subj = v['subjectfield'].text
assignment = v['message'].text
main()
def cancel_action(sender):
smtpserver.close()
ui.close_all()
def main():
global email_user, sendto, subj, assignment
header = 'To: ' + sendto + '\n' + 'From: ' + email_user + '\n' + 'Subject: ' + subj +'\n'
msg = header + assignment + '\n'
smtpserver.sendmail(email_user, sendto, msg)
sent_time = time.strftime("%A, %B %d, %Y at %I:%M:%S %p.", time.localtime())
console.hud_alert('Your message has been sent successfully on ' + sent_time, 'success', 2.1)
v['tofield'].text = ''
v['subjectfield'].text = ''
v['message'].text = ''
def login():
global email_user, email_pwd
info = console.login_alert('title', 'Enter your login credentials')
if info == None:
console.hud_alert('Login Cancelled', 'error', 1.5)
else:
email_user = info[0]
email_pwd = info[1]
setup()
def setup():
global email_user, email_pwd, v
v = ui.load_view('myemail')
send = ui.ButtonItem()
send.title = 'Send'
send.action = send_action
v.right_button_items = [send]
fromfield = v['fromfield']
fromfield.text = email_user
fromfield.scroll_enabled = False
v['tofield'].clear_button_mode = 'while_editing'
v['subjectfield'].clear_button_mode = 'while_editing'
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(email_user, email_pwd)
v.present('sheet')
providers = dialogs.list_dialog(title='Select Your Email Provider', items=["Gmail", "AOL", "Yahoo!", "Comcast", "Outlook"], multiple=False)
if providers == 'Gmail':
smtpserver = smtplib.SMTP("smtp.gmail.com",587)
elif providers == 'AOL':
smtpserver = smtplib.SMTP("smtp.aol.com",587)
elif providers == 'Yahoo!':
smtpserver = smtplib.SMTP("smtp.mail.yahoo.com",587)
elif providers == 'Comcast':
smtpserver = smtplib.SMTP("smtp.comcast.net",587)
elif providers == 'Outlook':
smtpserver = smtplib.SMTP("smtp-mail.outlook.com",587)
login()