本博客需要利用Python代码给自己的QQ邮箱发送自定义邮件,其进阶版就是要在服务器端把进程的错误信息实时转发给QQ邮箱,实现远程的操控。
一、原始版代码:
# -*- coding: utf-8 -*-
import smtplib
from email.mime.text import MIMEText
SMTPserver = 'smtp.qq.com'
sender = 'sender's QQ num@qq.com'
password = "sender's password"
message = 'I send a message by Python. 你好'
msg = MIMEText(message)
msg['Subject'] = 'Test Email by Python'
msg['From'] = sender
msg['To'] = 'receiver's QQ num@qq.com'
mailserver = smtplib.SMTP(SMTPserver, 25)
mailserver.login(sender, password)
mailserver.sendmail(sender, [sender], msg.as_string())
mailserver.quit()
print 'send email success'