#編碼:utf-8
導入smtplib
來自電子郵件。導入MIMEMultipart
來自電子郵件。導入MIMEBase
來自電子郵件。MIMEText導入MIMEText
導入操作系統,日期時間
def send_email(**kwargs):
"""
方法
事件
dtstart
由於
味精
dtstamp
"""
ical = " " "
BEGIN:VCALENDAR\r\n
PRODID:pyICSParser\r\n
方法:%(方法)s\r\n
版本:2.0\r\n
開始:%(事件)秒\r\n
DTSTART:%(dtstart)s\r\n
到期:%(到期)s\r\n
優先級:1\r\n
摘要:%(郵件)s\r\n
UID:cal SRV . example . com-873970198738777-00 @ example . com \ r \ n
序列:0\r\n
DTSTAMP:%(dtstamp)s\r\n
狀態:%(狀態)s\r\n
結束:VEVENT\r\n
結束:VCALENDAR\r\n
" " " % kwargs
eml_body = u"%(msg)s" % kwargs
msg = MIMEMultipart('mixed ')
msg[' Date ']= format Date(local time = True)
msg[' Subject ']= u " %(msg)s " % kwargs
msg['To'] = ","加入(與會者)
part_email = MIMEText(eml_body," html "," utf-8 ")
part_cal = MIMEText(ical,' calendarmethod=%(method)s'%kwargs,' utf-8 ')
msg alternative = mime multipart(' alternative ')
msg . attach(msg可選)
ical _ atch = mime base(' application/ics ',');name="%s"'%("invite.ics "))
ical_atch.set_payload(ical)
encoders . encode _ base64(ical _ atch)
ical _ atch . add _ header(' Content-Disposition ','附件;filename="%s"'%("invite.ics "))
eml_atch = MIMEBase('text/plain ','')
encoders . encode _ base64(EML _ atch)
eml_atch.add_header('內容傳輸編碼',"")
msg alternative . attach(part _ email)
msgAlternative.attach(part_cal)
s = smtplib。SMTP()
s . connect(“xxxx”)
s.login(' ',' ')
s.sendmail('auto@sys.com ',attendees,msg.as_string())
關閉()
與會者=['x@sys.com']
fro = " "
ddtstart = datetime . datetime . utc now()
dur = datetime.timedelta(分鐘= 5)
dtend = ddtstart + dur
dtend = dtend . strftime(" % Y % M % dT % H % M % SZ ")
Send _ email (method =' publish ',event =' vtoto ',dtstart = dtend,due = dtend,msg =' publish task ',dtstamp = dtend,status = "completed ")。
Send _ email (method =' request ',event =' vtoto ',dtstart = dtend,due = dtend,msg =' request task ',dtstamp = dtend,status = "needs action ")。
Send _ email (method =' publish ',event =' vevent ',dtstart = dtend,due = dtend,msg =' publish calendar ',dtstamp = dtend,status = "confirmed ")。
Send _ email (method =' request ',event =' vevent ',dtstart = dtend,due = dtend,msg = '請求日歷',dtstamp = dtend,status = '已確認')。