擅长:python、mysql、java
<p>假设您使用的是Python-2.x</p>
<p>您可以使用<code>smtplib</code>模块发送电子邮件,<code>csv</code>模块读取csv文件。在</p>
<p>此外,要使用<code>smtplib</code>,您必须有一个用于发送电子邮件的电子邮件地址,无论电子邮件是Yahoo mail或Gmail或其他任何东西。在</p>
<p>一些示例代码如下:</p>
<pre><code>#!/usr/bin/python
import csv
import smtplib
from email.mime.text import MIMEText
from email.Header import Header
def sendmail(info_list):
msg = MIMEText(info_list[2], "html", "utf-8")
msg['Subject'] = Header("YOUR SUBJECT", "utf-8")
msg['From'] = "FROM_WHOM@XXX.com"
msg['To'] = info_list[1]
s = smtplib.SMTP("smtp.XXX.com")
s.ehlo()
s.starttls()
s.login("YOUR EMAIL USERNAME", "YOUR EMAIL PASSWORD")
s.sendmail("FROM_WHOM", info_list[1], msg.as_string())
def main():
with open("msg.csv", "rb") as csvfile:
msg_reader = csv.reader(csvfile)
msg_reader.next()
map(lambda x: sendmail(x), msg_reader)
if __name__ == "__main__":
main()
</code></pre>