美文网首页
email 发送邮件

email 发送邮件

作者: Canon_2020 | 来源:发表于2020-04-20 09:09 被阅读0次
    #!/usr/local/python3
    # -*- coding: utf-8 -*-
    # @Date    : 2018-04-15 09:00:00
    # @Author  : Canon
    # @Link    : https://www.python.org
    # @Version : 3.6.1
    
    """
    发送邮件
    """
    
    import os
    import re
    import sys
    import json
    import difflib
    import smtplib
    from email.mime.text import MIMEText
    import tarfile
    
    
    # ---------- 发送邮件相关参数------
    # 发件服务器
    smtp_server = "smtp.exmail.qq.com"
    # 端口
    port = 465
    # 账号
    sender = "canon@oceanpayment.com.cn"
    # 密码
    psw = "Neng2018"
    # 接收人
    receiver = ["canon@oceanpayment.com.cn", "alan@oceanpayment.com.cn", "ron@oceanpayment.com.cn",
                "lomo@oceanpayment.com.cn", "dick@oceanpayment.com.cn", "carol@oceanpayment.com.cn"]
    
    
    def send_email(body):
        """
        发送邮件
        :param body: 邮件内容
        """
        # ---------- 编辑邮件内容 ------
        # 定义邮件正文为 html 格式
        msg = MIMEText(body, "html", "utf-8")
        # 发送人
        msg['from'] = sender
        # 接收人
        msg['to'] = ";".join(receiver)
        # 邮件标题
        subject = "镜像环境, 配置文件检查"
        msg['subject'] = subject
    
        # ---------- 发送邮件 ------
        flag = 1
        try:
            smtp = smtplib.SMTP()
            # 连接服务器
            smtp.connect(smtp_server)
            # 登录服务器
            smtp.login(sender, psw)
        except:
            flag = 0
            print("\tERROR - 邮箱登录失败")
            # # 连接服务器
            # smtp = smtplib.SMTP_SSL(smtp_server, port)
            # # 登录服务器
            # smtp.login(sender, psw)
    
        if flag:
            # 发送邮件
            smtp.sendmail(sender, receiver, msg.as_string())
            # 关闭服务器
            smtp.quit()
    
    

    相关文章

      网友评论

          本文标题:email 发送邮件

          本文链接:https://www.haomeiwen.com/subject/vspxuqtx.html