Python uses two ways of sending mail SMTP and Outlook samples

Source: Internet
Author: User
This article mainly describes the use of two kinds of Python e-mail SMTP and Outlook samples, with a certain reference value, interested in small partners can refer to.

SMTP is an SMTP server that calls 163 of mailboxes directly and needs to be set up in 163 mailboxes. The Outlook send is the Python call Win32 method directly. Callers Outlook sends messages 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 = ' 182982 68658 ' 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 = SMTPL Ib. 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) 
Related Article

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.