Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending Emails With smtplib In Python

I am trying to send emails with Gmail through the SMTPlib, it works fine when I send them to myself, but every time I try to send an email to someone else it still sends it to my own email.

import smtplib as s

username = raw_input("Gmail Username: ")
password = raw_input("Gmail Password: ")
obj = s.SMTP("smtp.gmail.com:587")
obj.starttls()
obj.login(username, password)
v_email = raw_input("Email: ")
email_message = raw_input("Message: ")
obj.sendmail(username, v_email, email_message)
like image 668
Max00355 Avatar asked May 04 '26 06:05

Max00355


1 Answers

Look a the example http://docs.python.org/library/smtplib.html, check how 'msg' is populated before passing to smtplib.sendmail()

like image 80
dpp Avatar answered May 05 '26 18:05

dpp