#!/usr/bin/env python
#coding=utf-8
#Author: Ca0Gu0
import time
import smtplib
from email.mime.text import MIMEText class MailCli(object):
def __init__(self):
self.s = smtplib.SMTP() #类实例化 def connect(self, host=None, port=25):
self.s.connect(host, port) #连接邮件服务器 def login(self, user=None, passwd=None):
self.user = user
self.s.login(user, passwd) #登陆帐户跟密码 def send(self, subject=None, content=None, to=None):
froms = self.user+'<%s>' %(self.user)
msg = MIMEText(content) #处理发件内容
msg['Subject'] = subject #处理发件主题
msg['From'] = froms #处理发件人地址
msg['To'] = to #处理收件人地址
self.s.sendmail(froms, to, msg.as_string()) #发送邮件内容
return "OK" def close(self):
self.s.close() #退出登陆
return '' #显示发信成功 if __name__ == "__main__":
host = "mail.xxx.com"
port = 25
user = "caoguo@xxx.com"
passwd = "password"
to = "caoguo@163.com" r=MailCli()
r.connect(host=host,port=port)
r.login(user=user, passwd=passwd) for i in range(10): #连续发生10封邮件 subject = "Testing SMTP Authentication "+ str(i)
content = "This mail tests SMTP Authentication" + str(i)
returns = r.send(subject=subject, content=content, to=to)
print time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time())),returns
r.close()

python发送文本邮件的更多相关文章

  1. python实现发送文本邮件

    简单实现了python发送文本邮件 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2018/4/25 17:09 # @Author ...

  2. 【Python开发】python发送各类邮件的方法

    转载: python发送各类邮件的主要方法 python中email模块使得处理邮件变得比较简单,今天着重学习了一下发送邮件的具体做法,这里写写自己的的心得,也请高手给些指点. 一.相关模块介绍 发送 ...

  3. 使用python发送163邮件 qq邮箱

    使用python发送163邮件 def send_email(title, content): import smtplib from email.mime.multipart import MIME ...

  4. 【python】使用python发送文本内容邮件

    下面提供了一个使用python做的发送文本内容的邮件代码,能够在邮件内容中设置文字颜色,大小,换行等功能. #auther by zls #_*_coding:utf-8_*_ import sys ...

  5. python发送各类邮件的主要方法

    更多详见: http://www.w3cschool.cc/python/python-email.html python中email模块使得处理邮件变得比较简单,今天着重学习了一下发送邮件的具体做法 ...

  6. 九、Python发送QQ邮件(SMTP)

    看了廖雪峰老师的教程: 一封电子邮件的旅程就是 发件人 -> MUA -> MTA -> MTA -> 若干个MTA -> MDA <- MUA <- 收件人 ...

  7. Python发送SMTP邮件指南

      SMTP(Simple Mail Transfer Protocol)简单邮件传输协议,Python内置对SMTP的支持,可以发送纯文本文件,HTML邮件以及附带文件.   一.两个模块 Pyth ...

  8. 使用python发送QQ邮件

    这里用到了Python的两个包来发送邮件: smtplib 和 email . Python 的 email 模块里包含了许多实用的邮件格式设置函数,可以用来创建邮件“包裹”.使用的 MIMEText ...

  9. python 发送安全邮件

    用python 写了一个发送邮件的脚本,配上host 和端口,发现一直报错: smtplib.SMTPException: No suitable authentication method foun ...

随机推荐

  1. sql sever 等待事件

    http://blog.csdn.net/dba_huangzj/article/details/7607844

  2. 拉普拉斯分布,高斯分布,L1 L2

    之前那篇文章里提到,L1其实是加上服从拉普拉斯分布的先验,L2是加上服从高斯分布的先验: http://www.cnblogs.com/charlesblc/p/7977732.html 那么记住拉普 ...

  3. Open Flash Chart2 常用的参数

    http://fyzeng.diandian.com/post/2011-07-29/3339982 {   /* 图表标题 */   "title" : {     " ...

  4. Linux经常使用命令002之搜索命令locate、whereis、which、find、grep

    Linux经常使用命令002之搜索命令locate.whereis.which.find.grep -20150811 经常使用搜索命令 -------文件搜索命令---------- -->l ...

  5. 5分钟Serverless实践 | 构建无服务器图片鉴黄Web应用

    Serverless是什么 Serverless中文译为“无服务器”,最早可以追溯到2012年Ken Fromm发表的<Why The Future Of Software And Apps I ...

  6. POJ 3221 Diamond Puzzle.

    ~~~~ 题目链接:http://poj.org/problem? id=3221 显然是BFS找最优解.但是终止条件不好写.看到有一仅仅队交上去一直TLE. 比赛完了看题解原来是以目标状态为起点,B ...

  7. Android 触摸提示音【转】

    本文转载自:http://blog.csdn.net/Jin_HeZai/article/details/46791567 近期任务,涉及Android触摸提示音. 首先,定位源码目标.很显然的,在原 ...

  8. IDEA 中Spark SQL通过JDBC连接mysql数据库

    一.IDEA装驱动: 1.下载一个MySQL的JDBC驱动:mysql-connector-java-5.1.44.tar.gz2.在idea Open Moudle Settings 在 Moudl ...

  9. hibernate中id中的 precision 和 scale 作用

    转自:https://www.cnblogs.com/IT-Monkey/p/4077570.html <hibernate-mapping>     <class name=&qu ...

  10. ::before和::after伪元素的使用

    :before和:after伪元素在CSS中可以被用来添加元素.加小标.清浮动等. 基本用法: p::before {} p::after {} 1.string <style type=&qu ...