Python3.0 my dailyreport script (2) email sending module

Source: Internet
Author: User

In fact, I don't use python. I installed python3.0 with the wind. I watched manual in a few days and wrote a daily report script to play with it. It doesn't matter if I use it. It feels quite helpful.

I heard that Chinese emails were sent in pyhon2.x or earlier in the old age, which is painful. It seems that I have caught up with the times. python3.0 sent some emails.CodeIt is still relatively easy to paste the metabolic products:

 

Code
# ! /Usr/bin/ENV Python
# Coding = UTF-8
# ! /Usr/bin/ENV Python
# Coding = UTF-8
# Author: haozes
# Email sending module
Import Sys
Import Smtplib
From Email. Mime. Image Import Mimeimage
From Email. Mime. multipart Import Mimemultipart
From Email. Mime. Text Import Mimetext
From Email. Header Import Header
From Email Import Utils

Class Mailsender:
_ From = None
To = None
CC = None
_ Subject = None
Html = None
Text = None
Def   _ Init __ (Self, smtpsvr, Port ):
Self. SMTP = Smtplib. SMTP ()
Self. SMTP. Connect (smtpsvr, Port)

Def Login (self, user, PWD ):
Self. _ from = User
Self. SMTP. login (user, PWD)

Def Setsubject (self, sub ):
Self. _ subject = Header (sub, ' UTF-8 ' )

Def Send (Self ):
MSG = Mimemultipart ( ' Alternative ' )
MSG [ ' Subject ' ] = Self. _ subject
MSG [ ' From ' ] = Self. _ from
MSG [ ' To ' ] = Self.
MSG [ ' CC ' ] = Self. CC
Mailto = Self. to. Split ( ' , ' )
If (Self. CC ! = None ):
Mailto. Extend (self. CC. Split ( ' , ' ))
Print (Mailto)
If Self. Text ! = None:
Part1 = Mimetext (self. Text. encode (), ' Plain ' , _ Charset = ' UTF-8 ' )
MSG. Attach (Part1)
If Self.html ! = None:
Part2 = Mimetext(self.html. encode (), ' Html ' , _ Charset = ' UTF-8 ' )
MSG. Attach (Part2)

Self. SMTP. Sendmail (self. _ from, mailto, MSG. as_string ())
Self. SMTP. Quit ()


If   _ Name __   =   " _ Main __ " :
Pass







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.