Skip to content Skip to sidebar Skip to footer

Adding Subject To The Email - Python

I am trying to send an email with a subject, i have the email working but unable to get the subject working, what can I do to fix this? This is the code that I have: fromaddr =

Solution 1:

Attach it as a header:

message = 'Subject: %s\n\n%s' % (SUBJECT, TEXT) and then:

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

Also consider using standard Python module email - it will help you a lot while composing emails.

Solution 2:

This will work.

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')

Post a Comment for "Adding Subject To The Email - Python"