zoukankan      html  css  js  c++  java
  • email_fun.py

    import smtplib
    from email.mime.text import MIMEText
    from email.utils import formataddr

    def mail():
      ret = 123
      try:
        msg = MIMEText('the mail contents', 'plain', 'utf-8')
        msg['From'] = formataddr(['NameA', 'Email_addr_S'])
        msg['To'] = formataddr(['nameB', 'Email_addr_R'])
        msg['Subject'] = "Subject"

        server = smtplib.SMTP('smtp.126.com', 25)
        server.login('Email_addr_S','PSD')
        server.sendmail('Email_addr_S',['Email_addr_R',],msg.as_string())
        server.quit
      except Exception:

        ret = 456
      return ret

    ret = mail()
    print(ret)

    mail_fun.py

    import smtplib
    from email.mime.text import MIMEText
    from email.utils import formataddr

    class mail():
      classSpec = "it is a test class"
      def __init__(self,UserName,UserAddr):
        self.UserName = UserName
        self.UserAddr = UserAddr

      def mail():

        ret = True
        try:
          msg = MIMEText('the mail contents', 'plain', 'utf-8')
          msg['From'] = formataddr(['NameA', 'Email_addr_S'])
          msg['To'] = formataddr(['nameB', 'Email_addr_R'])
          msg['Subject'] = "Subject"

          server = smtplib.SMTP('smtp.126.com', 25)
          server.login('Email_addr_S','PSD')
          server.sendmail('Email_addr_S',['Email_addr_R',],msg.as_string())
          server.quit
        except Exception:

          ret = False

        return ret

    email_call.py

    #! /usr/lib/python3.5

    import mail_fun

    worker1 = mail_fun.mail('xxx', 'xxxx@qq.com')
    ret = worker1.Semail()
    if ret:
      print('sent already')
    else:
      print('failed to send the email')

  • 相关阅读:
    第六篇 面向对象
    第四篇 函数
    基本http服务性能测试(Python vs Golang)
    七种常见经典排序算法总结(C++)
    461. Hamming Distance and 477. Total Hamming Distance in Python
    2. Add Two Numbers——Python
    21. Merge Two Sorted Lists —— Python
    求两个数字的最大公约数-Python实现,三种方法效率比较,包含质数打印质数的方法
    20. Valid Parentheses
    Python列表去除重复元素
  • 原文地址:https://www.cnblogs.com/tlfox2006/p/7229198.html
Copyright © 2011-2022 走看看