• 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

  • 相关阅读:
    Eclipse 中使用 ctrl 无法追踪函数的问题
    AJAX跨域问题
    eclipse设置svn代理
    同步IO和异步IO
    阿里云配置redis
    Centos +django+nginx
    Centos 安装nginx
    django 给前端传递HTML内容
    django项目初探
    python邮件服务
  • 原文地址:https://www.cnblogs.com/amuge/p/6235382.html
Copyright © 2020-2023  润新知