Skip to content

Commit 351cf10

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent a298b46 commit 351cf10

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

scripts/send_email_using_smtp_in_tornado.py

+15-13
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,28 @@
22
import tornado.ioloop, tornado.web
33
import smtplib
44

5+
56
# Function for sending mail
6-
def sendEmail(recipient_email, app_name):
7+
def sendEmail(recipient_email, app_name):
78
sender_email = ""
89
app_password = ""
910
# SMTP config
1011
smtp_server = "smtp.gmail.com"
1112
smtp_port = 587
12-
13+
1314
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+
1617
email_message = "Subject: %s\n\n%s" % (subject, body)
17-
18+
1819
try:
1920
server = smtplib.SMTP(smtp_server, smtp_port)
2021
server.starttls()
2122
server.login(sender_email, app_password)
2223
server.sendmail(sender_email, recipient_email, email_message)
2324
print("Email sent successfully")
2425
email_sent = True
25-
26+
2627
except smtplib.SMTPAuthenticationError as e:
2728
print("SMTP Authentication Error: %s" % e)
2829
except Exception as e:
@@ -33,7 +34,6 @@ def sendEmail(recipient_email, app_name):
3334
raise Exception("Email sending failed.")
3435

3536

36-
3737
# Async testing function
3838
async def asyncFunc(i):
3939
await asyncio.sleep(1)
@@ -45,19 +45,21 @@ async def main():
4545
print("Code started")
4646

4747
# Code for sending mail
48-
try:
48+
try:
4949
recipient_email = "[email protected]"
5050
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)
5456
except Exception as e:
5557
print(e)
5658

5759
for i in range(0, 10):
5860
await asyncFunc(i)
59-
6061

61-
if __name__ == '__main__':
62+
63+
if __name__ == "__main__":
6264
loop = asyncio.get_event_loop()
6365
loop.run_until_complete(main())

0 commit comments

Comments
 (0)