python_study's People
python_study's Issues
python_send_mail
#!/usr/bin/env python
-- coding: UTF-8 --
'''
发送txt文本邮件
'''
import smtplib
from email.mime.text import MIMEText
import os
import socket, fcntl, struct
mailto_list=["[email protected]", "[email protected]"]
mail_host="smtp.sohu.com" #设置服务器
mail_user="hopeaktian" #用户名
mail_pass="tf1998225" #口令
mail_postfix="sohu.com" #发件箱的后缀
def get_ip(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', ifname[:15]))[20:24])
def send_mail(to_list,sub,content):
me="hopeaktian"+"<"+mail_user+"@"+mail_postfix+">"
msg = MIMEText(content, 'plain', 'utf-8')
msg['Subject'] = sub
msg['From'] = me
msg['To'] = ";".join(to_list) #将收件人列表以‘;’分隔
try:
server = smtplib.SMTP()
server.connect(mail_host) #连接服务器
server.login(mail_user,mail_pass) #登录操作
server.sendmail(me, to_list, msg.as_string())
server.close()
return True
except Exception, e:
print str(e)
return False
if name == 'main':
myip=get_ip("ens33")
print myip
mes="你好,树莓派刚刚开机了,IP地址为:"+myip
print mes
for i in range(2): #发送1封,上面的列表是几个人,这个就填几
if send_mail(mailto_list,"树莓派开机IP",mes):
print "发送成功"
else:
print "发送失败"
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.