-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathemails.py
More file actions
69 lines (56 loc) · 2.07 KB
/
Copy pathemails.py
File metadata and controls
69 lines (56 loc) · 2.07 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from fastapi import (BackgroundTasks, UploadFile,
File, Form, Depends, HTTPException, status)
from dotenv import dotenv_values
from pydantic import BaseModel, EmailStr
from typing import List
from fastapi_mail import FastMail, MessageSchema, ConnectionConfig
import jwt
from models import User
config_credentials = dict(dotenv_values(".env"))
conf = ConnectionConfig(
MAIL_USERNAME=config_credentials["EMAIL"],
MAIL_PASSWORD=config_credentials["PASS"],
MAIL_FROM=config_credentials["EMAIL"],
MAIL_PORT=587,
MAIL_SERVER="smtp.gmail.com",
MAIL_TLS=True,
MAIL_SSL=False,
USE_CREDENTIALS=True
)
class EmailSchema(BaseModel):
email: List[EmailStr]
async def send_email(email: list, instance: User):
token_data = {
"id": instance.id,
"username": instance.username
}
token = jwt.encode(token_data, config_credentials["SECRET"])
template = f"""
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div style=" display: flex; align-items: center; justify-content: center; flex-direction: column;">
<h3> Account Verification </h3>
<br>
<p>Thanks for choosing EasyShopas, please
click on the link below to verify your account</p>
<a style="margin-top:1rem; padding: 1rem; border-radius: 0.5rem; font-size: 1rem; text-decoration: none; background: #0275d8; color: white;"
href="http://localhost:8000/verification/?token={token}">
Verify your email
<a>
<p style="margin-top:1rem;">If you did not register for EasyShopas,
please kindly ignore this email and nothing will happen. Thanks<p>
</div>
</body>
</html>
"""
message = MessageSchema(
subject="EasyShopas Account Verification Mail",
recipients=email, # List of recipients, as many as you can pass
body=template,
subtype="html"
)
fm = FastMail(conf)
await fm.send_message(message)