[root@os py]# cat mail_html.py
#!/usr/bin/python
import smtplib
import time
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.image import MIMEImage
mail_from="test@126.com"
mail_to="test@qq.com"
mail_host="smtp.126.com"
mail_user="test"
mail_password="test"
f=open("log.txt")
file=f.read()
mail_body=file
msg=MIMEText("
hello world
","html","utf-8")
msg["subject"]="subject"
def sendmail():
try:
smtp=smtplib.SMTP()
smtp.connect(mail_host)
smtp.login(mail_user,mail_password)
smtp.sendmail(mail_from,mail_to,msg.as_string())
smtp.quit()
except Exception ,e:
print e
if __name__ == "__main__":
sendmail()
[root@os py]# cat mail_fujian.py
#!/usr/bin/python
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
mail_from="test@126.com"
mail_to="test@qq.com"
mail_host="smtp.126.com"
mail_user="test"
mail_password="test"
body="this is test mail"
msg=MIMEMultipart(body)
mail_body=MIMEText(body)
msg["subject"]="subject"
att=MIMEText(open('/data/py/1.gif','rb').read(),'base64','gb2312')
att["Content-Type"] = 'application/octet-stream'
att["Content-Disposition"] = 'attachment; filename="1.gif"'
msg.attach(att)
msg.attach(mail_body)
def sendmail():
try:
smtp=smtplib.SMTP()
smtp.connect(mail_host)
smtp.login(mail_user,mail_password)
smtp.sendmail(mail_from,mail_to,msg.as_string())
smtp.quit()
except Exception ,e:
print e
if __name__ == "__main__":
sendmail()
[root@os py]# cat mail1.py
#!/usr/bin/python
import smtplib
from email.mime.text import MIMEText
mail_from="test@126.com"
mail_to="test@qq.com"
mail_host="smtp.126.com"
mail_user="test"
mail_password="test"
f=open("log.txt")
file=f.read()
mail_body=file
msg=MIMEText(mail_body)
msg["subject"]="subject"
def sendmail():
try:
smtp=smtplib.SMTP()
smtp.connect(mail_host)
smtp.login(mail_user,mail_password)
#smtp.sendmail(mail_from,[mail_to,mail_cc,mail_cc1],msg.as_string())
smtp.sendmail(mail_from,mail_to,msg.as_string())
smtp.quit()
except Exception ,e:
print e
if __name__ == "__main__":
sendmail()
阅读(1370) | 评论(0) | 转发(0) |