email_fun.py

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

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:ui

    ret = 456
  return retorm

ret = mail()
print(ret)server

 

 

mail_fun.pyutf-8

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

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

  def mail():io

    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:
form

      ret = Falseclass

    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')

本站公眾號
   歡迎關注本站公眾號,獲取更多信息