First come to SMTP send
import smtplib from email.mime.text import MIMEText from email.header import Header def mail(): "" through SMTP """ # third-party SMTP service mail_host = "mail.xxx.com" # Set up the server mail_user = "xxx.com\xxxx.zhu" # username domain account and domain mail_pass = "Email" # passwordsender = 'xx' # receivers = ["] # receivers = MIMEText('... ', 'plain', 'utf-8') message [' From '] = Header (" novice tutorial ", "utf-8") the message [' To '] = Header (" test ", 'utF-8 ') subject = 'Python SMTP test' message[' subject '] = Header(subject, 'utF-8 ') try: SmtpObj = smtplib.smtp () smtpobj.connect (mail_host, 587) # 25 smtpobj.login (mail_user, Mail_pass) smtpobj. sendmail(sender, receivers, message.as_string()) print(" Email sent successfully ") except smtplib.SMTPException: Print ("Error: could not send mail ") Exchange sendCopy the code
# -*- coding:utf-8 -*- from exchangelib import DELEGATE, Account, Credentials, Message, Mailbox, HTMLBody class Exchange(object): def __init__(self, account, pwd, sendmail): self.account = account self.pwd = pwd self.sendmail = sendmail self.credentials = Credentials(self.account, Self.pwd) self.account = account (primary_smtp_address=sendmail, # The credentials= sendmail, Autodiscover =True, access_type=DELEGATE) def mail(self, *args): M = Message(Account =self.account, subject=args[0], body=HTMLBody(args[1]), to_recipients=[Mailbox(email_address=args[2])] ) m.send() # if __name__ == '__main__': # Send = Exchange (" xxx.com \ XXX. Zhu, "' your password ', 'your E-mail account') #. Send mail (" email", 'content', 'receiving mailboxes')Copy the code