2
2
import tornado .ioloop , tornado .web
3
3
import smtplib
4
4
5
+
5
6
# Function for sending mail
6
- def sendEmail (recipient_email , app_name ):
7
+ def sendEmail (recipient_email , app_name ):
7
8
sender_email = ""
8
9
app_password = ""
9
10
# SMTP config
10
11
smtp_server = "smtp.gmail.com"
11
12
smtp_port = 587
12
-
13
+
13
14
subject = "Android App Created: %s" % app_name
14
- body = ''' Your Android app %s has been successfully created.''' % app_name
15
-
15
+ body = """ Your Android app %s has been successfully created.""" % app_name
16
+
16
17
email_message = "Subject: %s\n \n %s" % (subject , body )
17
-
18
+
18
19
try :
19
20
server = smtplib .SMTP (smtp_server , smtp_port )
20
21
server .starttls ()
21
22
server .login (sender_email , app_password )
22
23
server .sendmail (sender_email , recipient_email , email_message )
23
24
print ("Email sent successfully" )
24
25
email_sent = True
25
-
26
+
26
27
except smtplib .SMTPAuthenticationError as e :
27
28
print ("SMTP Authentication Error: %s" % e )
28
29
except Exception as e :
@@ -33,7 +34,6 @@ def sendEmail(recipient_email, app_name):
33
34
raise Exception ("Email sending failed." )
34
35
35
36
36
-
37
37
# Async testing function
38
38
async def asyncFunc (i ):
39
39
await asyncio .sleep (1 )
@@ -45,19 +45,21 @@ async def main():
45
45
print ("Code started" )
46
46
47
47
# Code for sending mail
48
- try :
48
+ try :
49
49
recipient_email = "[email protected] "
50
50
app_name = "myApp"
51
- tornado .ioloop .IOLoop .current ().run_in_executor (None , sendEmail , recipient_email , app_name )
52
- # You can directly call the function for async
53
- # sendEmail(recipient_email, app_name)
51
+ tornado .ioloop .IOLoop .current ().run_in_executor (
52
+ None , sendEmail , recipient_email , app_name
53
+ )
54
+ # You can directly call the function for async
55
+ # sendEmail(recipient_email, app_name)
54
56
except Exception as e :
55
57
print (e )
56
58
57
59
for i in range (0 , 10 ):
58
60
await asyncFunc (i )
59
-
60
61
61
- if __name__ == '__main__' :
62
+
63
+ if __name__ == "__main__" :
62
64
loop = asyncio .get_event_loop ()
63
65
loop .run_until_complete (main ())
0 commit comments