env_values = dotenv_values(".env")
env_values = dict(env_values)
config = ConnectionConfig(
MAIL_USERNAME =env_values["USER"],
MAIL_PASSWORD = env_values["PASSWORD"],
MAIL_FROM = env_values["USER"],
MAIL_PORT = 587,
MAIL_SERVER = "smtp.gmail.com",
MAIL_STARTTLS = True,
MAIL_SSL_TLS = False,
USE_CREDENTIALS = True,
VALIDATE_CERTS = True
)
async def send_verification_mail(token : str, user_mail : EmailStr):
template = f"""
<!DOCTYPE html>
<html lang="en">
<head>
<title>mail service</title>
</head>
<body>
<p>Sign up process invoked <a href="http://localhost:8000/email_verification/{token}">click here</a> to verify</p>
<p> <b>NOT YOU </b><a href="http://localhost:8000/email_verification_revoke/{token}">click here</a> to revoke</p>
</body>
</html>
"""
message = MessageSchema(
subject="Email verification for stackoverflow clone",
recipients=[user_mail], # List of recipients, as many as you can pass
body = template,
subtype="html"
)
try:
fm = FastMail(config=config)
await fm.send_message(message)
return True
except:
print("message not sent")
return False
I am trying to send email through fastapi_mail but it is giving error as key error : 1011
in File “D:projectstackoverflow clone backendenvLibsitepackagesuvicornprotocolshttphttptools_impl.py”, line 476, in send
content = [STATUS_LINE[status_code]]
KeyError: 1011
I was expecting it to work but it isnt