Example #1
0
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

fromadd = '*****@*****.**'
toaddr = '*****@*****.**'
text = 'text message sent from python'
username ='******'
password = '******'
msg = MIMEMultipart()
msg['From']= fromadd
msg['To'] = toaddr
msg['Subject'] = 'Test'
msg.attach(MIMEText(text))
server = smtplib.SMTP('smtp.gmail.com:507')
server.ehlo()
server.starttls()
server.ehlo()
server.login(username, password)
server.sendmail(fromadd, toadd, msg.as_tring())
server.quit()
Example #2
0
#Definimos las cabeceras del Email

remitente = user
destinatario = input('Para ejemplo: [email protected]')
asunto = input('asunto')
mensaje = input('mensaje')

#host y puerto SMTP Gmail

gmail = smtplib.SMTP('smtp.gmail.com', '587')

#Aqui comienza la transferencia
gmail.starttls()

gmail.login(user, password)

gmail.set_debuglevel(1)

header = MIMEMultipart()
header['Subject'] = asunto
header['From'] = remitente
header['To'] = destinatario

#convertir a html
mensaje = MIMEText(mensaje, 'html')
header.attach(mensaje)

gmail.sendmail(remitente, destinatario, header.as_tring())

gmail.quit()