2014-05-08 2 views
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

가 헤더로 연결합니다 :

메시지 =이 내가 가진 그 코드 '제목 : %의 \ n \ n % s의'% (제목, 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') 
관련 문제