I use an API with works fine on my local machine, but not when I deploy it. I can access the API correctly, but however, I am not able to run the sendmail
function anymore. This is the code:
def is_valid_email(email):
if len(email) > 7:
return bool(
re.match("^.+@(\[?)[a-zA-Z0-9-.]+.([a-zA-Z]{2,3}|[0-9]{1,3})(]?)$", email)
)
def sendmail(name, email):
msg = EmailMessage()
msg["Subject"] = "Confirmation email"
msg["From"] = "mymail.com"
msg["To"] = email
msg.set_content(
f"Hallo {name},\n\nDanke für deine Email. Ich werde mich zeitnah um dein Anliegen kümmern.\n\nViele Grüße\nxxx"
)
with smtplib.SMTP_SSL("smtp.gmail.com", 465) as smtp:
smtp.login("mymail.com", "password")
smtp.send_message(msg)
@api.route("/makerequest")
class MakeRequest(Resource):
def post(self):
name = request.get_json()["name"]
email = request.get_json()["email"]
text = request.get_json()["text"]
if is_valid_email(email) is False:
return {"message": "Invalid Email"}, 401
sendmail(name, email)
return {"message": "mail sent successfully"}, 200
This is the error I receive: flask | smtplib.SMTPAuthenticationError: (534, b'5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbv\n5.7.14
I don´t use a firewall currentl and the less secure apps are allowed. The provided username and password are correct, they work on my local machine. What can be the reason that it does not work on my server and how to fix it?