python发送文本邮件
#!/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发送文本邮件的更多相关文章
- python实现发送文本邮件
简单实现了python发送文本邮件 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2018/4/25 17:09 # @Author ...
- 【Python开发】python发送各类邮件的方法
转载: python发送各类邮件的主要方法 python中email模块使得处理邮件变得比较简单,今天着重学习了一下发送邮件的具体做法,这里写写自己的的心得,也请高手给些指点. 一.相关模块介绍 发送 ...
- 使用python发送163邮件 qq邮箱
使用python发送163邮件 def send_email(title, content): import smtplib from email.mime.multipart import MIME ...
- 【python】使用python发送文本内容邮件
下面提供了一个使用python做的发送文本内容的邮件代码,能够在邮件内容中设置文字颜色,大小,换行等功能. #auther by zls #_*_coding:utf-8_*_ import sys ...
- python发送各类邮件的主要方法
更多详见: http://www.w3cschool.cc/python/python-email.html python中email模块使得处理邮件变得比较简单,今天着重学习了一下发送邮件的具体做法 ...
- 九、Python发送QQ邮件(SMTP)
看了廖雪峰老师的教程: 一封电子邮件的旅程就是 发件人 -> MUA -> MTA -> MTA -> 若干个MTA -> MDA <- MUA <- 收件人 ...
- Python发送SMTP邮件指南
SMTP(Simple Mail Transfer Protocol)简单邮件传输协议,Python内置对SMTP的支持,可以发送纯文本文件,HTML邮件以及附带文件. 一.两个模块 Pyth ...
- 使用python发送QQ邮件
这里用到了Python的两个包来发送邮件: smtplib 和 email . Python 的 email 模块里包含了许多实用的邮件格式设置函数,可以用来创建邮件“包裹”.使用的 MIMEText ...
- python 发送安全邮件
用python 写了一个发送邮件的脚本,配上host 和端口,发现一直报错: smtplib.SMTPException: No suitable authentication method foun ...
随机推荐
- samba 奇怪问题
有一个centos 7 samba服务器,配置如下: [root@proxy223 20150331]# cat /etc/samba/smb.conf [global] workgroup = W ...
- ubuntu tweak Install
ubuntu tweak 1:增加PPA源 sudo add-apt-repository ppa:tualatrix/ppa 2:編輯源列表sudo gedit /etc/apt/sources.l ...
- [JavaEE] Bootstrapping a JavaEE Application
To bootsrap the application use the following Maven archetype: mvn -DarchetypeGroupId=org.codehaus.m ...
- FTPClientUtil FTPclient工具
package com.ctl.util; //须要commons-net-3.0.1.jar import java.io.*; import java.net.*; import java.uti ...
- HDU 1973
Prime Path Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- MyEclipse 9.0 正式版公布新闻 下载
MyEclipse 9.0 正式版公布 新闻 ============================================================================ ...
- oracle11g 手工建库步骤
#create oracle instance parameter vi initkevin.or db_name='kevin' memory_target=0 sga_max_size=5G sg ...
- 【bzoj1207】[HNOI2004]打鼹鼠
看了数据范围,想想这不暴力可以过?? DP #include<algorithm> #include<iostream> #include<cstdlib> ...
- SoapUI项目书写自我规范
-->Assertions 判断某个节点存在(_input_name, _button_name) -->Resource 文件夹命名 值去掉红色部分信息 https://mercury- ...
- basename与dirname命令解析【转】
本文转载自:http://blog.csdn.net/choice_jj/article/details/8766335 basename命令 语法:basename string [suffix] ...