可能是由以下几个原因引起的:
以下是一个示例代码,演示如何使用Python的smtplib库发送电子邮件:
import smtplib
from email.mime.text import MIMEText
def send_email():
# 邮件服务器配置
smtp_host = 'smtp.example.com'
smtp_port = 25
smtp_user = 'your_username'
smtp_password = 'your_password'
# 邮件内容
sender = 'sender@example.com'
receiver = 'receiver@example.com'
subject = 'Test Email'
body = 'This is a test email.'
# 创建邮件对象
msg = MIMEText(body, 'plain')
msg['Subject'] = subject
msg['From'] = sender
msg['To'] = receiver
try:
# 连接邮件服务器并发送邮件
server = smtplib.SMTP(smtp_host, smtp_port)
server.login(smtp_user, smtp_password)
server.sendmail(sender, receiver, msg.as_string())
server.quit()
print('Email sent successfully!')
except Exception as e:
print('Failed to send email:', str(e))
send_email()
请注意,以上代码仅为示例,实际使用时需要替换为你自己的邮件服务器配置和邮件内容。
领取专属 10元无门槛券
手把手带您无忧上云