Python uses two mail Methods: smtp and outlook, pythonsmtp

Source: Internet
Author: User

Python uses two mail Methods: smtp and outlook, pythonsmtp

Smtp is the smtp server that directly calls 163 mailbox. You need to set it in 163 mailbox. In outlook, Python directly calls the win32 method. Call the program outlook to send an email directly.

import win32com.client as win32 import xlrd outlook = win32.Dispatch('outlook.application') mail = outlook.CreateItem(0) receivers = ['Yutao.A.Wang@alcatel-sbell.com.cn'] mail.To = receivers[0] mail.Subject ='test1' workbook = xlrd.open_workbook('E:\\kpi excel\\00_summary.xls') mySheet = workbook.sheet_by_index(0)  nrows = mySheet.nrows content = [] for i in range(nrows):  ss = mySheet.row_values(i)  content.append(ss)  print(content)  Truecontent =str(content)  mail.Body = Truecontent mail.Attachments.Add('E:\\kpi excel\\00_summary.xls') mail.Send() 

Smtp send mail

import smtplib from email.mime.text import MIMEText mail_host = 'smtp.163.com' mail_user = '18298268658' mail_pass = 'cat123' sender = '18298268658@163.com' receivers = ['619538553@qq.com']  message = MIMEText('content','plain','utf-8') message['Subject'] = 'title' message['From'] = sender message['To'] = receivers[0]  try:  smtpObj = smtplib.SMTP()  smtpObj.connect(mail_host,25)  smtpObj.login(mail_user,mail_pass)  smtpObj.sendmail(   sender,receivers,message.as_string())  smtpObj.quit()  print('success') except smtplib.SMTPException as e:  print('error',e) 

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.