首先我要声明一点,代码语言为Python语言但是特别简单,就算没学过也能玩
编程语言:Python
工具:idea
环境:PythonSDK(idea在你下载Python插件 之后一般会自动下载)
第一步:
安装idea的Python插件,并选择SDK(如已安装,请跳过)
setting-->plugins-->Python
第二步:
创建Python项目,并在项目下依次创建:
文件夹letter-->letter_1.txr 这个是我们邮件的主体信息,稍后会在代码中引用
Hey [NAME]Hey Buddy, Today is Valentine's Day, I wish you a happy Valentine's Day.Lots of loveSwayam
信息文件 valentine.csv
name,email姓名(暂不支持中文,可自行调整),邮箱
主体Python运行文件 main.py
import datetime as dtimport pandasimport randomimport smtplibmy_email = "你的邮箱账户"passw = "你在邮箱中开启的smtp密码(如果之前没有开启过,可在各大邮箱网站登录后设置(具体百度))"data = pandas.read_csv("valentine.csv")name = data["name"].tolist()email = data["email"].tolist()friends = []for n in range(len(name)): friends.append( { "name": name[n], "email": email[n] } )if not friends: print("no email")else: for friend in friends: with open("letters/letter_1.txt") as letter: lines = letter.readlines() lines[0].strip() lines[0] = lines[0].replace("[NAME]", friend["name"]) message = "".join(lines) with smtplib.SMTP("smtp.163.com") as connection: connection.starttls() print("登录账户中...") connection.login(user=my_email, password=passw) print("登陆成功!") print("正在给"+friend["name"]+"发送邮件中...") connection.sendmail(from_addr=my_email, to_addrs=friend["email"], msg="Subject: HAPPY TODAYnn"+message) print("message sent to "+friend["name"]) print("账户退出")
好啦
如果你不知道idea中运行Python文件,可使用快捷键:Ctrl+Shift+F10