0

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 = ("email@gmail.com")
toaddrs  = (emailAdd1)
subject1 = ("Update")

msg = (body2)

username = 'email@gmail.com'
password = 'password'

server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(username,password)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
user3605290
  • 33
  • 2
  • 4
  • 1
    Look at this topic: http://stackoverflow.com/questions/7232088/python-subject-not-shown-when-sending-email-using-smtplib-module – rtrevizan May 08 '14 at 20:53

2 Answers2

0

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.

James
  • 37
  • 1
  • 9
0

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')
Benedito
  • 105
  • 4