安装PyEmail
pip install PyEmail
python代码
import smtplib
from email.mime.text import MIMEText
smtp_server = "smtp.example.com"
smtp_user = "[email protected]"
smtp_password = "your_password"
smtp_connection = smtplib.SMTP(smtp_server)
smtp_connection.login(smtp_user, smtp_password)
email_body = "This is a test email sent using Python."
email_message = MIMEText(email_body)
email_message["Subject"] = "Test Email"
email_message["From"] = smtp_user
email_message["To"] = "[email protected]"
smtp_connection.sendmail(smtp_user, "[email protected]", email_message.as_string())
smtp_connection.quit()
常用的邮箱的SMTP服务器地址
- 阿里云邮箱(mail.aliyun.com):smtp.aliyun.com(SSL加密端口:465;非加密端口:25)
- 谷歌邮箱(google.com):smtp.gmail.com(SSL启用端口:587)
- 新浪邮箱(sina.com): smtp.sina.com.cn(端口:25)
- Tom邮箱(top.com):smtp.tom.com(端口:25)
- 网易邮箱(163.com):smtp.163.com(端口:25)
- 126邮箱:smtp.126.com(端口:25)
- 雅虎邮箱(yahoo.com):smtp.mail.yahoo.com
- Foxmail邮箱(foxmail.com):SMTP.foxmail.com(端口:25)
- QQ邮箱(mail.qq.com):smtp.qq.com(端口:25)SMTP服务器需要身份验证。
- 搜狐邮箱(sohu.com):smtp.sohu.com(端口:25)
- HotMail邮箱(hotmail.com):SMTP服务器地smtp.live.com(端口:587)
- 移动139邮箱: SMTP.139.com(端口:25)