-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmyemail.py
31 lines (24 loc) · 1.4 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
import os
import sys
import smtplib
def send_email(receiver, activation_number, subject):
receiver_email = receiver
sender_email = os.environ['EMAIL_SENDER']
sender_pwd = os.environ['EMAIL_PASSWORD']
sender_user = os.environ['USER_SENDER']
smtpserver = smtplib.SMTP(os.environ['EMAIL_SERVER'], 587) #not self hosted.
smtpserver.ehlo() #Identify yourself to an ESMTP server using EHLO
smtpserver.starttls() #Requests the mail server to start TLS/SSL negotiation and protect the connection with security layer.
smtpserver.login(sender_user, sender_pwd)
if subject=='activation':
msg_header = 'To:' + receiver_email + '\n' + 'From: ' + sender_email + '\n' + 'Subject: Email Confirmation \n'
msg_intro = '\n Thank you for registering. To activate your account click here: \n\n'
activation_link = "http://localhost:5000/activation/" + str(activation_number)
if subject=='forgot_pass':
msg_header = 'To:' + receiver_email + '\n' + 'From: ' + sender_email + '\n' + 'Subject: Reset Password \n'
msg_intro = '\n You requested a password reset. To continue with this process, please click here: \n\n'
activation_link = "http://localhost:5000/reset/" + str(activation_number)
msg_content = msg_intro + activation_link
msg = msg_header + msg_content
smtpserver.sendmail(sender_email, receiver_email, msg)
smtpserver.close()