python简单的发送邮件
python 利用smtplib来发送邮件,具体的代码如下
一、 编辑smtp_v2.py
vim /home/python/smtp_v2.py
#!/usr/bin/env python
# -*- encoding:utf-8 -*- '''欢迎使用python smtp''' import smtplib from email.mime.text import MIMEText
from email.utils import formataddr
from email.header import Header smtp_host = 'smtp.sina.com'
smtp_port = 25 mail_user = 'test@sina.com'
mail_pwd = '这里输入发送邮箱的登录密码' sender = 'test@sina.com'
receivers = ['test@sina.com','test@qq.com'] message = MIMEText('Python邮件发送测试...','plain','utf-8')
message['From'] = formataddr(['小灰哥',sender])
message['To'] = formataddr(['测试',receivers[0]]) subject = Header('python 测试一二三','utf-8')
message['Subject'] = subject try:
smtpObj = smtplib.SMTP(smtp_host,smtp_port)
#smtpObj.connect(mail_host,smtp_port)
smtpObj.login(mail_user,mail_pwd)
smtpObj.sendmail(sender,receivers,message.as_string())
print '邮件发送成功'
smtpObj.quit()
except smtplib.SMTPException ,e:
print 'Error:无法发送邮件',e
二、执行脚本
python smtp_v2.py

python简单的发送邮件的更多相关文章
- python -- 简单配置发送邮件功能
本文用第三方类库:yagmail 实现:以QQ邮箱作为发送邮箱为例.最终的实现效果:给指定邮箱,发送指定内容的邮件. 准备工作 1.用于发送邮件的账号信息 比如账号用自己的qq邮箱,但'密码'需要在邮 ...
- python使用smtplib发送邮件
python要实现发送邮件的功能,需要使用smtplib库. 1. 过程大致如下: 1. 建立和SMTP邮件服务器的连接 # 默认端口25 smtp = smtplib.SMTP(host, port ...
- Python简单爬虫入门三
我们继续研究BeautifulSoup分类打印输出 Python简单爬虫入门一 Python简单爬虫入门二 前两部主要讲述我们如何用BeautifulSoup怎去抓取网页信息以及获取相应的图片标题等信 ...
- Python简单爬虫入门二
接着上一次爬虫我们继续研究BeautifulSoup Python简单爬虫入门一 上一次我们爬虫我们已经成功的爬下了网页的源代码,那么这一次我们将继续来写怎么抓去具体想要的元素 首先回顾以下我们Bea ...
- 亲身试用python简单小爬虫
前几天基友分享了一个贴吧网页,有很多漂亮的图片,想到前段时间学习的python简单爬虫,刚好可以实践一下. 以下是网上很容易搜到的一种方法: #coding=utf-8 import urllib i ...
- GJM : Python简单爬虫入门(二) [转载]
感谢您的阅读.喜欢的.有用的就请大哥大嫂们高抬贵手"推荐一下"吧!你的精神支持是博主强大的写作动力以及转载收藏动力.欢迎转载! 版权声明:本文原创发表于 [请点击连接前往] ,未经 ...
- Selenium + PhantomJS + python 简单实现爬虫的功能
Selenium 一.简介 selenium是一个用于Web应用自动化程序测试的工具,测试直接运行在浏览器中,就像真正的用户在操作一样 selenium2支持通过驱动真实浏览器(FirfoxDrive ...
- 【美妙的Python之中的一个】Python简单介绍及环境搭建
美妙的Python之Python简单介绍及安装 简而言之: Python 是能你无限惊喜的语言,与众不同. 1.Python: ...
- python通过SMTP发送邮件失败,报错505/535
python通过SMTP发送邮件失败:错误1:smtplib.SMTPAuthenticationError: (550, b'User has no permission') 我们使用pyth ...
随机推荐
- Centos下yum配置lnmp环境
首先关闭SELINUX vi /etc/selinux/config #SELINUX=enforcing #注释掉 #SELINUXTYPE=tar ...
- Java基础-绘图技术
- .NET 文件相关的所有操作
public static class FileSystemHelper { #region 检测指定目录是否存在 /// <summary> /// 检测指定目录是否存在 /// < ...
- [Flex] PopUpButton系列 —— 打开和关闭弹出菜单
<?xml version="1.0" encoding="utf-8"?><!--响应打开和关闭弹出菜单的例子 PopUpButtonOpe ...
- (easy)LeetCode 231.Power of Two
Given an integer, write a function to determine if it is a power of two. Credits:Special thanks to @ ...
- (easy)LeetCode 202.Happy Number
Write an algorithm to determine if a number is "happy". A happy number is a number defined ...
- null 之AddAll、Add和Boolean
@Test //failed public void TestListAddAll(){ List<TravelerInfo> travelerInfoSummary=new ArrayL ...
- JQuery上传插件uploadify整理(Events)
Arguments fileThe file object being cancelled onCancel:调用calcel方法.$('#upload').uploadify('cancel'); ...
- UIPickView 和 UIDatePicker
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- Redis多机功能之复制
复制的目的:创建具有相同数据库的拷贝服务器:扩展系统处理读请求的能力: 复制的定义 Redis的复制(replication)功能允许用户根据一个Redis服务器来创建任意多个该服务器的复制品,其中被 ...