python发邮件

 #!/usr/bin/python
# -*- coding: UTF-8 -*-
import smtplib
from email.mime.text import MIMEText
import string
mailto_list=["XX@163.com","XXX@163.com"]
print mailto_list
mail_host="smtp.exmail.qq.com" #设置服务器
mail_user="XX@qq.com" #用户名
mail_pass="passwd" #口令
neirong="<ul><li><font size=\"2\">12345</font></li></ul>" def send_mail(to_list,sub,content): #定义一个函数,收件人、标题、邮件内容
me="hello"+"<"+mail_user+">" #发件人定义,这里要和认证帐号一致才行的
msg = MIMEText(content,_subtype='html',_charset='utf-8') #这里看email模块的说明,这里构造内容
msg['Subject'] = sub
msg['From'] = me
# msg['To'] = string.join(mailto_list,",") #这是2中的一种写法,通过string.join()函数,可以把元组中的各个字段以“,”分隔,和下面达到一样的效果
msg['To'] = ",".join(mailto_list) #这种在2和3都可以用,在3中,string模块中取消了join()函数,join()函数作为一个全局函数被使用
try:
server = smtplib.SMTP()
server.connect(mail_host)
# server.starttls()
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__': #做个判断,当直接调用的时候才执行这个函数,什么是直接调用?就是我直接执行这个脚本的时候就是直接调用,如果我在别的脚本导入这个脚本在执行就是间接调用
if send_mail(mailto_list,"hello",neirong):
print "发送成功"
else:
print "发送失败"

python发送html格式的邮件的更多相关文章

  1. 使用Python发送HTML格式的邮件(收到的邮件有发送方才是正解)

    发送html格式的和普通文本格式差不多,只是MIMEText(content,"html","utf-8"))与MIMEText(content,"p ...

  2. python - 发送html格式的邮件

    import smtplibfrom email.mime.multipart import MIMEMultipartfrom email.mime.text import MIMETextfrom ...

  3. python 发送带附件的邮件

    特别注意的地方:filespart.add_header("Content-Disposition","attachment",filename=file_na ...

  4. 在Linux命令行下发送html格式的邮件

    在Linux利用formail+sendmail来发送带图片的邮件 formail接收html格式的文件作为邮件的内容,这样就可以解决发送带图片邮件的问题了,因为html中可以插入图片,只要给出的im ...

  5. Python发送带附件的邮件

    看别人的博客就不要在往别人的邮箱里发东西了行不行, 有点素质可以吗!!! 写出来分享还不知道珍惜!!!!! #-*-encoding:utf-8 -*- import os import smtpli ...

  6. 【代码片段】Python发送带图片的邮件

    # coding=utf-8 import smtplib from email.mime.text import MIMEText from email.mime.multipart import ...

  7. java mail发送html格式的邮件

    // 获取系统属性 Properties properties = System.getProperties(); // 设置邮件服务器 properties.setProperty("ma ...

  8. python 发送带附件的 邮件

    from email.MIMETextimportMIMETextfrom email.MIMEMultipartimportMIMEMultipartimport smtplib mail_host ...

  9. Django -- 发送HTML格式的邮件

    提前在setting中设置邮箱server from django.core.mai import EmailMessage subject, from_email, to = 'xxx', 'nor ...

随机推荐

  1. svn安装教程

    svn服务器端下载(VisualSVN) 安装包,选择windows版的VisualSVN-Server https://www.visualsvn.com/downloads/ svn客户端下载(T ...

  2. NetBeans使用Consolas中文乱码的解决

    1.进入jdk安装目录下/jre/lib文件夹,找到fontconfig.properties.src,拷贝为 fontconfig.properties ,修改此文件. 找到: sequence.m ...

  3. 【WPF】ImageMagick调节图片的颜色

    需求:打开一张图片后,自由调节图片的颜色(色调). 思路:读取显示一张图片后,用ColorPicker取色器选择一种颜色,之后将图片的色调调节为该颜色. 工具: 1.图像工具 ImageMagick( ...

  4. linux下从一台服务器复制文件或文件夹到本地

    1.从服务器复制文件到本地:scp root@×××.×××.×××.×××:/data/test.txt /home/myfile/ root@×××.×××.×××.×××   root是目标服务 ...

  5. abtestingGateway错误集锦

    管理接口访问报错 系统版本 内核版本 Ubuntu 14.04.2 3.13.0-32-generic 我们在这里通过curl来插入命令的时候直接报错: curl命令写入规则 curl 'http:/ ...

  6. 【App】Android Studio 海马玩

    一.工程创建及配置 1.gradle环境变量 2.首次创建工程慢:https://www.cnblogs.com/xiadewang/p/7820377.html 二.海马玩虚拟机 C:\Users\ ...

  7. vue2.0 在微信端如何使用本地IP访问项目

    我们会遇到这样的需求,在PC端开发vue脚手架项目,希望在微信端随时浏览页面(如果打包再发布到服务器又太麻烦),怎么办? 思路很简单:保证手机和电脑在同一个IP下,用同一个IP访问项目,这样就可以了: ...

  8. One example to understand SemFix: Program Repair via Semantic Analysis

    One example to understand SemFix: Program Repair via Semantic Analysis Basic Information Authors: Ho ...

  9. 用SUMIF对超15位的代码进行条件求和,出错了,原因是....

    用SUMIF对超15位的代码进行条件求和,出错了,原因是.... 2017-10-29 23:01 一.问题 有读者朋友问: 用SUMIF进行条件求和时,如果统计的条件是超15位的代码,就会出错,比如 ...

  10. J - Network of Schools

    来源poj1236 A number of schools are connected to a computer network. Agreements have been developed am ...