简单实现了python发送文本邮件

 #!/usr/bin/env python
# -*- coding: utf-8 -*- # @Time : 2018/4/25 17:09
# @Author : zms
# @Site :
# @File : SendEmail.py
# @Software: PyCharm Community Edition import time
from email.mime.text import MIMEText
import smtplib class SendEmail(object):
def __init__(self):
self.port = 25
self.fromemail = 'test@test.com'
self.emailpasswd = '******' def sendemail(self, subject, msg, fromemail=None, emailpasswd=None, toemail=None):
'''实现发送邮件功能函数'''
if fromemail == None | emailpasswd == None:
_user = self.fromemail
_pwd = self.emailpasswd
else:
_user = fromemail
_pwd = emailpasswd
_to = toemail
nowtime = time.strftime('%Y-%m-%d %H:%M:%S') msg = MIMEText(msg)
msg["Subject"] = subject
msg["From"] = _user
msg["To"] = _to try:
# s = smtplib.SMTP_SSL('****.****.cn', 25)
s = smtplib.SMTP('****.****.cn', self.port)
s.login(_user, _pwd)
s.sendmail(_user, _to, msg.as_string())
s.quit()
print "[%s]INFO:%s Email send Success!" % (nowtime, _to)
except smtplib.SMTPException, e:
print "[%s]ERROR:%s Email send Falied,%s" % ((nowtime, e), _to) if __name__ == '__main__':
email = SendEmail()
email.sendemail('test', 'test', 'test@test.com', '******', 'test@test.com')

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

  1. python发送文本邮件

    #!/usr/bin/env python #coding=utf-8 #Author: Ca0Gu0 import time import smtplib from email.mime.text ...

  2. python 快速发送大量邮件

    因为公司需求,需要发送千万封级别邮件. # coding:utf-8 import csv import smtplib from email.mime.text import MIMEText im ...

  3. python——SMTP发送简单邮件

    [root@localhost python]# cat smtp.py import smtplib import string from email.mime.text import MIMETe ...

  4. python初级实战-----关于邮件发送问题

    python发邮件需要掌握两个模块的用法,smtplib和email,这俩模块是python自带的,只需import即可使用.smtplib模块主要负责发送邮件,email模块主要负责构造邮件. sm ...

  5. python定时利用QQ邮件发送天气预报

    大致介绍 好久没有写博客了,正好今天有时间把前几天写的利用python定时发送QQ邮件记录一下 1.首先利用request库去请求数据,天气预报使用的是和风天气的API(www.heweather.c ...

  6. 接口测试基础——第一篇smtplib发送文字邮件

    现在我们就开始进入接口测试框架的知识准备阶段,今天是第一篇,很简单的,就是发送纯文字的电子邮件,会的童鞋可以忽略,不会的就多敲几遍,直到自己能敲出来为止~~ # coding: utf-8 impor ...

  7. spring boot发送其他邮件

    前面已经讲了使用springboot采用常规的javaweb方式发送邮件和使用spring模板发送邮件.但是发送的都是文本文件,现在来说一下使用spring模板发送一些其他的邮件. 1.pom.xml ...

  8. SpringBoot整合Mail发送邮件&发送模板邮件

    整合mail发送邮件,其实就是通过代码来操作发送邮件的步骤,编辑收件人.邮件内容.邮件附件等等.通过邮件可以拓展出短信验证码.消息通知等业务. 一.pom文件引入依赖 <dependency&g ...

  9. Python模块探秘之smtplib,实现纯文本邮件的发送

    今天学到了如何使用Python的smtplib库发送邮件,中间也是遇到了各种各样的错误和困难,还好都一一的解决了.下面来谈一谈我的这段经历. 配置你的邮箱 为什么要配置邮箱呢?具体要配置什么呢? 因为 ...

随机推荐

  1. 【LeetCode】智商题 brainteaser(共3题)

    [292]Nim Game [319]Bulb Switcher [777]Swap Adjacent in LR String (2019年2月13日,谷歌tag) 给了两个字符串start 和en ...

  2. HTML超链接应用场景

    页面间的连接 A页到B页,最常用,用于网络导航. 如图所示: ********************************************************************* ...

  3. 线程安全与非线程安全集合说一下,底层怎么实现的(hashmap,concurrenthashmap)

    Hashmap本质是数组加链表.根据key取得hash值,然后计算出数组下标,如果多个key对应到同一个下标,就用链表串起来,新插入的在前面. ConcurrentHashMap:在hashMap的基 ...

  4. Flutter-showBottomSheet底部彈出框

    onPressed: () { showModalBottomSheet( context: context, builder: (BuildContext context) { return new ...

  5. CF 36E Two Paths

    传送门 真实的自闭= =+ 考试的时候老师明明说了可以路径为空T^T 然后光荣的挂掉了 20分的链[明明是最送分的] 上来就看出来欧拉回路了嘛 然后思考了一下大概奇点配个对 删一条简单路径剩下的跑欧拉 ...

  6. Python 的 zip 和 dict 组合 生成新字典

    >>> d = dict(zip(['a', 'b'], [1, 2]))>>> d{'a': 1, 'b': 2}>>> d = dict(zi ...

  7. Web核心之Request对象

    HTTP协议中Request请求部分格式 //请求行(这种是POST类型的请求) POST /HttpServleLogin.html HTTP/1.1 //请求头(User-Agent里有Firef ...

  8. keras及神经网络,以简单实例入门

    由浅入深,深入浅出.还给你reference了很多,如果你想要更多. 迄今为止看到最棒的,最值得follow的入门tutorial: https://realpython.com/python-ker ...

  9. Junit单元测试之MockMvc

    在测试restful风格的接口时,springmvc为我们提供了MockMVC架构,使用起来也很方便. 下面写个笔记,便于以后使用时参考备用. 一 场景 1 . 提供一个restful风格的接口 im ...

  10. delphi WaitForSingleObject 示例之一等待另一个进程的结束

    <pre>unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Cont ...