Foros del Web » Programando para Internet » Python »

Error al enviar correo html

Estas en el tema de Error al enviar correo html en el foro de Python en Foros del Web. Buenas, Cuando intento enviar un correo HTML me da un error. Script @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código Python: Ver original # Send an HTML email with an ...
  #1 (permalink)  
Antiguo 29/01/2010, 10:07
Avatar de neodani  
Fecha de Ingreso: marzo-2007
Mensajes: 1.811
Antigüedad: 17 años
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!
  #2 (permalink)  
Antiguo 29/01/2010, 10:50
Avatar de razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años
Puntos: 1360
Respuesta: Error al enviar correo html

Código Python:
Ver original
  1. from smtplib import SMTP
  2. connection = SMTP('smtp.gmail.com', 587)
  3. connection.ehlo()
  4. connection.starttls()
  5. connection.ehlo()
  6. connection.login('<nombre_de_usuario>@gmail.com', '<Contraseña_Aqui>')
  7. connection.sendmail(strFrom, strTo, msgRoot.as_string())
  8. connection.quit()

Bueno por lo menos a mi me funciono correctamente.

Si se te hace mas facil puedes usar el modulo libgmail

Última edición por razpeitia; 01/02/2010 a las 09:22
  #3 (permalink)  
Antiguo 01/02/2010, 02:07
Avatar de neodani  
Fecha de Ingreso: marzo-2007
Mensajes: 1.811
Antigüedad: 17 años
Puntos: 20
Respuesta: Error al enviar correo html

Cita:
Iniciado por razpeitia Ver Mensaje
Código Python:
Ver original
  1. from smtplib import SMTP
  2. connection = smtplib.SMTP('smtp.gmail.com', 587)
  3. connection.ehlo()
  4. connection.starttls()
  5. connection.ehlo()
  6. connection.login('<nombre_de_usuario>@gmail.com', '<Contraseña_Aqui>')
  7. connection.sendmail(strFrom, strTo, msgRoot.as_string())
  8. connection.quit()

Bueno por lo menos a mi me funciono correctamente.

Si se te hace mas facil puedes usar el modulo libgmail
Uhm... al ponerlo me da error

connection = smtplib.SMTP('smtp.gmail.com', 587)
NameError: name 'smtplib' is not defined


Muchas gracias de antemano!
  #4 (permalink)  
Antiguo 01/02/2010, 09:23
Avatar de razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años
Puntos: 1360
Respuesta: Error al enviar correo html

Ya lo edite :P
Código Python:
Ver original
  1. from smtplib import SMTP
  2. connection = SMTP('smtp.gmail.com', 587)
  3. connection.ehlo()
  4. connection.starttls()
  5. connection.ehlo()
  6. connection.login('<nombre_de_usuario>@gmail.com', '<Contraseña_Aqui>')
  7. connection.sendmail('<Remitente>', '<Destinatario>', '<Aqui el mensaje>')
  8. connection.quit()

Última edición por razpeitia; 01/02/2010 a las 11:34
  #5 (permalink)  
Antiguo 02/02/2010, 05:06
Avatar de neodani  
Fecha de Ingreso: marzo-2007
Mensajes: 1.811
Antigüedad: 17 años
Puntos: 20
Respuesta: Error al enviar correo html

Cita:
Iniciado por razpeitia Ver Mensaje
Ya lo edite :P
Código Python:
Ver original
  1. from smtplib import SMTP
  2. connection = SMTP('smtp.gmail.com', 587)
  3. connection.ehlo()
  4. connection.starttls()
  5. connection.ehlo()
  6. connection.login('<nombre_de_usuario>@gmail.com', '<Contraseña_Aqui>')
  7. connection.sendmail('<Remitente>', '<Destinatario>', '<Aqui el mensaje>')
  8. connection.quit()
Muchas gracias razpeitia funcionó :)

Etiquetas: correo, enviar, html
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 10:13.