Jul-14-2017, 07:28 PM
Don't post code without
You never call function
Stuff shall not go from global namespace into a function,that why i mention arguments.
Tested work for me.
indentation
.You never call function
sendEmail()
or give arguments
to function.Stuff shall not go from global namespace into a function,that why i mention arguments.
Tested work for me.
import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart def send_email(from_addr, to_addr,subject, message): msg = MIMEMultipart() msg['From'] = from_addr msg['To'] = to_addr # Message of email msg['Subject'] = subject body = message msg.attach(MIMEText(body, 'plain')) # Server server = smtplib.SMTP('smtp.gmail.com', 587) server.starttls() server.login('[email protected]', 'password') text = msg.as_string() server.sendmail(fromaddr, toaddr, text) server.quit() if __name__ == '__main__': from_addr = "[email protected]" to_addr = "[email protected]" subject = 'Alien' message = 'Alien from mars attacks' # Call function send_email(from_addr, to_addr, subject, message)