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