这两日用到了python的发送邮件功能,恰好又想起来wordpress发送给我的邮件都是形如wordpress@leniy.info
的虚拟地址,于是我就上网查找了下伪造邮件发件人的方案。网上这些资料非常多,以下是个人感兴趣的部分内容的汇总。
声明:本系列文章均为博主个人学习中收集到的网络资源的汇总笔记,不保证其时效性安全性,请勿用于非正当途径。
原文标题:Python – Sending Email using SMTP
原文地址:/python/python_sending_email.htm
原文作者:tutorialspoint
相关内容:
Simple Mail Transfer Protocol (SMTP) is a protocol which handles sending e-mail and routing e-mail between mail servers.
Python provides smtplib module which defines an SMTP client session object that can be used to send mail to any Internet machine with an SMTP or ESMTP listener daemon.
Here is a simple syntax to create one SMTP object which can later be used to send an email:
import smtplib
smtpObj = smtplib.SMTP( [host [, port [, local_hostname]]] )
Here is the detail of the parameters:host: This is the host running your SMTP server. You can specifiy IP address of the host or a domain name like . This is optional argument.
port: If you are providing host argument then you need to specifiy a port where SMTP server is listening. Usually this port would be 25.
local_hostname: If your SMTP server is running on your local machine then you can specify just localhost as of this option.The sender – A string with the address of the sender.
The receivers – A list of strings, one for each recipient.
The message – A message as a string formatted as specified in the various RFCs.
#!/usr/bin/python
import smtplib
sender = 'from@'
receivers = ['to@']
message = """From: From Person
To: To Person
Subject: SMTP e-mail test
This is a test e-mail message.
"""
try:
smtpObj = smtplib.SMTP('localhost')
smtpObj.sendmail(sender, receivers, message)
print "Successfully sent email"
except SMTPException:
print "Error: unable to send email"