python
2014-05-08 98 views 0 likes 
0

我想發送一個主題的電子郵件,我有電子郵件工作,但無法讓主題工作,我能做些什麼來解決這個問題?這是代碼,我有:添加主題到電子郵件 - Python

fromaddr = ("[email protected]") 
toaddrs = (emailAdd1) 
subject1 = ("Update") 

msg = (body2) 

username = '[email protected]' 
password = 'password' 

server = smtplib.SMTP('smtp.gmail.com:587') 
server.starttls() 
server.login(username,password) 
server.sendmail(fromaddr, toaddrs, msg) 
server.quit() 
+1

看着這個主題: http://stackoverflow.com/questions/7232088/python-subject-not-shown-when-sending-email-using-smtplib-module – rtrevizan

回答

0

附上它作爲標頭:

消息= '主題:%S \ n \ n%s' 的%(SUBJECT,TEXT) 然後:

server = smtplib.SMTP(SERVER) 
server.sendmail(FROM, TO, message) 
server.quit() 

另外考慮使用標準的Python模塊電子郵件 - 它會幫助你很多,同時撰寫電子郵件。

0

這將工作。

def enviaremail(usuario,senha,listadestinatarios,subject,mensagem): 
    from smtplib import SMTP 
    from email.mime.text import MIMEText 

    msg=MIMEText(mensagem) 
    msg['From']=usuario 
    msg['To']=', '.join(listadestinatarios) 
    msg['Subject']=subject 

    smtp=SMTP('smtp.live.com',587) 
    smtp.starttls() 
    smtp.login(usuario,senha) 
    smtp.sendmail(usuario,listadestinatarios,msg.as_string()) 
    smtp.quit() 
    print('E-mail sent') 
相關問題