utils, generate pass and send email
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import random
|
||||
import string
|
||||
import smtplib
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
def generate_password(length=10):
|
||||
characters = string.ascii_letters + string.digits
|
||||
return ''.join(random.choice(characters) for _ in range(length))
|
||||
|
||||
def send_email(recipient_email, subject, body):
|
||||
sender_email = "your_email@example.com"
|
||||
sender_password = "your_email_password"
|
||||
|
||||
msg = MIMEText(body)
|
||||
msg['Subject'] = subject
|
||||
msg['From'] = sender_email
|
||||
msg['To'] = recipient_email
|
||||
|
||||
try:
|
||||
with smtplib.SMTP('smtp.gmail.com', 587) as server:
|
||||
server.starttls()
|
||||
server.login(sender_email, sender_password)
|
||||
server.send_message(msg)
|
||||
except Exception as e:
|
||||
print(f"Failed to send email: {e}")
|
||||
Reference in New Issue
Block a user