码迷,mamicode.com
首页 > 其他好文 > 详细

发送邮件

时间:2019-01-22 21:57:56      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:use   smtp   ==   邮箱   word   input   login   int   bsp   

 

yagmail

import yagmail

def login(user, pwd,host ,smtp_ssl):
    user = user     # 邮箱账号
    pwd = pwd       # 授权码,不是邮箱密码
    mail = yagmail.SMTP(user=user,
                        password=pwd,
                        host=‘smtp.163.com‘,# 服务器就 smtp.*.com
                        smtp_ssl=smtp_ssl  # 安全协议,非必须
                        )

def send_msd(to, cc, subject, contents, attachments):
    mail.send(
        to=[to,],                  #   多人写成列表[]
        cc=[cc,],                  #   抄送
        subject=subject,           #   邮件标题
        contents=contents,         #   邮件正文
        attachments=attachments)     #   多个附件写成列表[]

    print(‘发送成功‘)



if __name__ == ‘__main__‘:
    user = input(‘帐号:‘)
    pwd = input(‘授权码:‘)
    host = input(‘服务器:‘)
    smtp_ssl = input(‘是否启用安全服务:‘)
    login(user, pwd, host, smtp_ssl)

    to = input(‘请输入发送对象‘)
    cc = input(‘请输入抄送对象‘)
    subject = input(‘请输入邮件主题‘)
    contents = input(‘请输入邮件内容‘)
    attachments = input(‘请输入附件路径‘)
    send_msg(to, cc, subject, contents, attachments)

 

发送邮件

标签:use   smtp   ==   邮箱   word   input   login   int   bsp   

原文地址:https://www.cnblogs.com/ray-mmss/p/10305952.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!