1. 程式人生 > 其它 >python傳送郵件sendmail簡單指令碼

python傳送郵件sendmail簡單指令碼

技術標籤:smtp程式語言

#!/usr/bin/env python
# _*_ coding:utf-8 _*_
#author charkedy
def sendmail():
    import smtplib
    from email.mime.text import MIMEText
    from email.utils import formataddr

    msg=MIMEText('郵件內容','plain','utf-8')
    msg["From"]=formataddr(["凱迪沒有拉克",'[email protected]
']) msg["To"]=formataddr(["zkd",'[email protected]']) msg['Subject']=" 主題" user="[email protected]" passwd='25' server=smtplib.SMTP() server.connect(user,passwd) server.login("[email protected]",'郵箱密碼') #地址及密碼 server.sendmail('
[email protected]
',['[email protected]',],msg.as_string()) #由163郵箱發郵件至qq郵箱 server.quit() sendmail()