◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。
向其他人发送电子邮件是一件很重要的事情,在开发中它可以用来发送一些代码,如 otp、pin、身份验证等
最近,我有一个项目,需要我能够向用户发送电子邮件以获取 otp 代码,结果非常简单。
import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText # creates SMTP session s = smtplib.SMTP('smtp.gmail.com', 587) # start TLS for security s.starttls() # Authentication s.login("your_email@gmail.com", "yyaz pgow khtd xeqn") # Create a multipart message msg = MIMEMultipart() msg['From'] = "your_email@gmail.com" msg['To'] = "send_to_email@gmail.com" msg['Subject'] = "Subject of the Email" message = "How are you mate? This is a test email sent using Python" # Attach the message body msg.attach(MIMEText(message, 'plain')) # Send the email s.send_message(msg) # terminating the session s.quit()
如果您遇到任何困难,请随时提问:)
来源:
立即学习“Python免费学习笔记(深入)”;
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。