Ver Mensaje Individual
  #1 (permalink)  
Antiguo 29/01/2010, 10:07
Avatar de neodani
neodani
 
Fecha de Ingreso: marzo-2007
Mensajes: 1.811
Antigüedad: 17 años, 1 mes
Puntos: 20
Error al enviar correo html

Buenas,

Cuando intento enviar un correo HTML me da un error.

Script
Código Python:
Ver original
  1. # Send an HTML email with an embedded image and a plain text message for
  2. # email clients that don't want to display the HTML.
  3.  
  4. from email.MIMEMultipart import MIMEMultipart
  5. from email.MIMEText import MIMEText
  6. from email.MIMEImage import MIMEImage
  7.  
  8. # Define these once; use them twice!
  9. strFrom = '[email protected]'
  10.  
  11. # Create the root message and fill in the from, to, and subject headers
  12. msgRoot = MIMEMultipart('related')
  13. msgRoot['Subject'] = 'test message'
  14. msgRoot['From'] = strFrom
  15. msgRoot['To'] = strTo
  16. msgRoot.preamble = 'This is a multi-part message in MIME format.'
  17.  
  18. # Encapsulate the plain and HTML versions of the message body in an
  19. # 'alternative' part, so message agents can decide which they want to display.
  20. msgAlternative = MIMEMultipart('alternative')
  21. msgRoot.attach(msgAlternative)
  22.  
  23. msgText = MIMEText('This is the alternative plain text message.')
  24. msgAlternative.attach(msgText)
  25.  
  26. # We reference the image in the IMG SRC attribute by the ID we give it below
  27. msgText = MIMEText('<b>Some <i>HTML</i> text</b> and an image.<br><img src="cid:image1"><br>Nifty!', 'html')
  28. msgAlternative.attach(msgText)
  29.  
  30. # This example assumes the image is in the current directory
  31. fp = open('blue.jpg', 'rb')
  32. msgImage = MIMEImage(fp.read())
  33. fp.close()
  34.  
  35. # Define the image's ID as referenced above
  36. msgImage.add_header('Content-ID', '<image1>')
  37. msgRoot.attach(msgImage)
  38.  
  39. # Send the email (this example assumes SMTP authentication is required)
  40. import smtplib
  41. smtp = smtplib.SMTP()
  42. smtp.connect('smtp.gmail.com')
  43. smtp.login('[email protected]', '123456')
  44. smtp.sendmail(strFrom, strTo, msgRoot.as_string())
  45. smtp.quit()

El error que me arroja es el siguiente

Traceback (most recent call last):
File "enviar_correo_html.py", line 44, in <module>
smtp.login(''[email protected]', '123456')
File "C:\Python25\lib\smtplib.py", line 554, in login
raise SMTPException("SMTP AUTH extension not supported by server.")
smtplib.SMTPException: SMTP AUTH extension not supported by server.

¿Sabéis como puedo solucionarlo?

Muchas gracias de antemano!