Last active
January 31, 2018 12:35
-
-
Save fabiuxx/1ce5541b84db65c981fbad7b407b3e2d to your computer and use it in GitHub Desktop.
Script para envío de correos electrónicos utilizando gmail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import smtplib | |
import sys | |
from email.mime.multipart import MIMEMultipart | |
from email.mime.text import MIMEText | |
def send_email(user, pwd, recipient, subject, body): | |
gmail_user = user | |
gmail_pwd = pwd | |
FROM = user | |
TO = recipient | |
SUBJECT = subject | |
TEXT = body | |
# Create message container - the correct MIME type is multipart/alternative. | |
msg = MIMEMultipart('alternative') | |
msg['Subject'] = SUBJECT | |
msg['From'] = FROM | |
msg['To'] = TO | |
part = MIMEText(body, 'html') | |
msg.attach(part) | |
try: | |
server = smtplib.SMTP("smtp.gmail.com", 587) | |
server.ehlo() | |
server.starttls() | |
server.login(gmail_user, gmail_pwd) | |
server.sendmail(FROM, TO, msg.as_string()) | |
server.close() | |
print 'successfully sent the mail' | |
except Exception as e: | |
print "failed to send mail", e | |
if __name__ == '__main__': | |
send_email('[email protected]', '123456789987654321', '[email protected]', 'asunto', 'ola k ase?') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment