46 lines
1.1 KiB
Python
46 lines
1.1 KiB
Python
import smtplib
|
|
from smtplib import *
|
|
from email.message import EmailMessage
|
|
from random import randrange
|
|
import sqlite3
|
|
from datetime import datetime, timedelta
|
|
from verification import otp
|
|
from db import *
|
|
|
|
class mail:
|
|
|
|
def __init__(self, email):
|
|
self.email = email
|
|
|
|
def gen_code():
|
|
code = randrange(1000, 9999)
|
|
return code
|
|
|
|
def send(email, code):
|
|
try:
|
|
smtpObj = smtplib.SMTP_SSL('mail.example.com', 465)
|
|
|
|
# Identify yourself to an ESMTP server using EHLO
|
|
smtpObj.ehlo()
|
|
|
|
# Login to the server (if required)
|
|
smtpObj.login('email', 'password')
|
|
|
|
# Send an email
|
|
msg = EmailMessage()
|
|
msg.set_content(f'You have requested a verification code. Your code is {code}. This code expires in 5 minutes.')
|
|
|
|
msg['Subject'] = 'UWP Community Verification Code'
|
|
msg['From'] = "email@example.com"
|
|
msg['To'] = email
|
|
|
|
smtpObj.send_message(msg)
|
|
|
|
# Quit the SMTP session
|
|
smtpObj.quit()
|
|
except SMTPResponseException as e:
|
|
print(e)
|
|
|
|
|
|
|