Ich stoße auf ein Problem, während ich versuche, OTP -E -Mails mit SMTP (Simple Mail Transfer Protocol) in Python zu senden. Trotz der Überprüfung der angegebenen Anmeldeinformationen (E -Mail und Passwort) erhalte ich weiterhin einen Authentifizierungsfehler. https://support.google.com/mail/?p=BadCredentials
d75a77b69052e-4746b3106b9sm84101401cf.18 - gsmtp')
127.0.0.1 - - [05/Mar/2025 07:34:22] "PUT /xpassword http /1.1 "200 -
code < /p>
Hier ist das Code -Snippet, mit dem ich E -Mails senden kann: < /p>
Python < /p>
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from api.config import PASSWORD, MAIL
def send_otp(email, otp):
"""
Sends an OTP to the specified email address.
Args:
email (str): The recipient's email address.
otp (str): The OTP to be sent.
Sends the OTP via email using SMTP.
"""
sender_email = MAIL
sender_password = PASSWORD
subject = "Your OTP Code"
body = f"Your OTP code is {otp}. It is valid for 10 minutes."
message = MIMEMultipart()
message["From"] = sender_email
message["To"] = email
message["Subject"] = subject
message.attach(MIMEText(body, "plain"))
try:
server = smtplib.SMTP("smtp.gmail.com", 587)
# server.starttls() # Uncommented this if using TLS
server.login(sender_email, sender_password)
server.sendmail(sender_email, email, message.as_string())
server.quit()
except Exception as e:
print(f"Failed to send email: {e}")`
< /code>
Schritte zur Fehlerbehebung von
verifiziert, dass die E -Mail und das Kennwort korrekt sind.>
E -Mails können mit der SMTP Python Library nicht gesendet werden ⇐ Python
-
- Similar Topics
- Replies
- Views
- Last post
-
-
Senden von E -Mails mit dem Mailer -Flutter -Paket auf SMTP Outlook -Anbieter
by Anonymous » » in Android - 0 Replies
- 21 Views
-
Last post by Anonymous
-