3

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)
5
  • What do the email headers look like on the email that's sent? Commented Apr 26, 2012 at 23:44
  • Yeah, I don't see you adding the sender or any other headers to the e-mail. Which means the user is expected to type them as part of a message. Commented Apr 26, 2012 at 23:50
  • I am supposed to add From: and To: etc in it? Sorry I am new to this Commented Apr 27, 2012 at 0:00
  • yea, you have to call .mail(sender) and .rcpt(recipient) first. wikipedia has a nice example how smtp works. Commented Apr 27, 2012 at 0:09
  • Would anyone mind fixing my code? I am having trouble. Commented Apr 27, 2012 at 0:38

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks I should have looked at it more carefully.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.