使用python发送简单的邮件
from:http://blog.csdn.net/zhaoweikid/article/details/125898
前些时间,论坛上有人讨论怎么用python发送需要认证的邮件,我在我的FreeBSD在telnet到163的的smtp服务器,分析了一下,就用python写个了发送邮件的程序,感觉有点粗糙,但还算能工作。
import smtplib, base64
class SimpleSendMail:
def __init__(self, smtp_server, from_addr, to_addr, user, passwd):
self.from_addr = from_addr
self.to_addr = to_addr
self.username = base64.encodestring(user)
self.password = base64.encodestring(passwd)
self.mailserver = smtp_server
def send(self, msg):
server = smtplib.SMTP(self.mailserver)
server.set_debuglevel(1)
server.docmd("EHLO server")
server.docmd("AUTH LOGIN")
server.send(self.username)
server.getreply()
server.send(self.password)
server.getreply()
server.docmd("MAIL FROM:" + self.from_addr)
server.docmd("RCPT TO:" + self.to_addr)
server.docmd("DATA")
server.send(msg)
server.send("/r/n./r/n")
server.getreply()
#server.reset()
server.quit()
if __name__ == '__main__':
test = SimpleSendMail("smtp.163.com", "xxxx@163.com", "xxxx@sina.com", "xxxx", "xxxxxxxxx")
test.send("heheh/r/na test from python send mail")
使用python发送简单的邮件的更多相关文章
- 使用python发送和接收邮件
关于电子邮件 大学之前,基本不用邮箱,所以基本感觉不到它的存在,也不知道有什么用:然而大学之后,随着认识的人越来越多,知识越来越广泛,邮箱已然成为很重要的通讯工具,大学一些课程作业需要有邮箱发给老师, ...
- 【python】使用python发送文本内容邮件
下面提供了一个使用python做的发送文本内容的邮件代码,能够在邮件内容中设置文字颜色,大小,换行等功能. #auther by zls #_*_coding:utf-8_*_ import sys ...
- python 发送无附件邮件
import smtplibimport tracebackfrom email.mime.text import MIMETextfrom config.config import * ...
- SpringBoot发送简单文本邮件
1.pom.xml添加 spring-boot-starter-mail 依赖 <dependency> <groupId>org.springframework.boot&l ...
- 飘逸的python - 发送带各种类型附件的邮件
上一篇博文演示了如何发送简单的邮件,这一篇将演示如何发送各种类型的附件. 基本思路就是,使用MIMEMultipart来标示这个邮件是多个部分组成的,然后attach各个部分.如果是附件,则add_h ...
- Python通过yagmail和smtplib模块发送简单邮件
SMTP是发送邮件的协议,Python内置对SMTP的支持,可以发送纯文本邮件.HTML邮件以及带附件的邮件.python发邮件需要掌握两个模块的用法,smtplib和email,这俩模块是pytho ...
- python发送各类邮件的主要方法
更多详见: http://www.w3cschool.cc/python/python-email.html python中email模块使得处理邮件变得比较简单,今天着重学习了一下发送邮件的具体做法 ...
- 九、Python发送QQ邮件(SMTP)
看了廖雪峰老师的教程: 一封电子邮件的旅程就是 发件人 -> MUA -> MTA -> MTA -> 若干个MTA -> MDA <- MUA <- 收件人 ...
- python初级实战-----关于邮件发送问题
python发邮件需要掌握两个模块的用法,smtplib和email,这俩模块是python自带的,只需import即可使用.smtplib模块主要负责发送邮件,email模块主要负责构造邮件. sm ...
随机推荐
- Redis_php 学习
转载内容: PhpRedis是php的一个扩展,效率是相当高有链表排序功能,对创建内存级的模块业务关系很有用;以下是redis官方提供的命令使用技巧: Redis::__construct构造函数 1 ...
- C++下字符串转换
引用自:http://blog.sina.com.cn/s/blog_a98e39a20101ari9.html 把最近用到的各种unicode下类型转换总结了一下,今后遇到其他的再补充: 1.str ...
- PHP 判断用户是否手机访问
$agent = check_wap(); if( $agent ) { header('Location: http://www.lewanau.com'); exit; } // check if ...
- Android-怎样用命令行进行打包
转载请标明出处:http://blog.csdn.net/goldenfish1919/article/details/40978859 1.生成R文件 aapt package -f -m -J . ...
- Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.FileUtils
1.错误叙述性说明 警告: Could not create JarEntryRevision for [jar:file:/D:/MyEclipse/apache-tomcat-7.0.53/web ...
- Jmail的邮件发送
下载注册dll文件 1. dll文件下载 2.到jmail.dll所在目录,运行cmd regsvr32 目录/jmail.dll 3.c#程序中,行首引用代码 using jmail C#示例代码 ...
- xcode 高亮
Cmd+E, Cmd+F and Cmd+G combo is usefull. Depending on why you want to do this, edit all in scope (Ct ...
- iOS开发中常用到的加密方式
1 base64 1.1 简介 Base64编码的思想是是采用64个基本的ASCII码字符对数据进行重新编码.它将需要编码的数据拆分成字节数组.以3个字节为一组.按顺序排列24位数据,再把这24位数据 ...
- 快速安装VIM开发环境
*Mac上当前用户的.vim目录打包*:附件地址:http://pan.baidu.com/s/1sj5FjZJ 1. 备份好系统的原来的vim配置文件,以备恢复使用: mv ~/.v ...
- c语言,strcmp(),字符串比较,看Asic 码,str1>str2,返回值 > 0;两串相等,返回
#include<stdio.h> #include<string.h> int main() { char *buffer1="aaa",*buffer ...