0

I'm kind of confused about how subprocess.Popen works. If anyone has example code that sends email using the subprocess module and sendmail that'd be great.

4
  • 3
    Out of curiosity, why sendmail instead of Python's smtplib? Commented Dec 21, 2009 at 20:09
  • actually right now i'm using smtplib, but for some reason the To: address doesn't show up in emails. Commented Dec 21, 2009 at 20:56
  • Wouldn't it make more sense to ask (via posting the code in question) why the To: address doesn't show up in the emails? Commented Dec 21, 2009 at 21:01
  • @Joe, I provided an answering showing why you probably aren't getting the To address to show up in the headers. If that works for you, please accept it but first edit your question to summarize this series of comments and make it clear the accepted answer doesn't address the question as described in its title... Commented Dec 21, 2009 at 21:04

2 Answers 2

2

This doesn't directly answer the question, but given your response to a comment by "DNS", it might solve your problem.

When sending SMTP mail, you need to understand that the "from" and "to" addresses that you pass to the smtplib.sendmail() routine as arguments are not the same thing as what you see in the From: and To: headers in the message when it's received. Those arguments become parameters given to the receiving SMTP mailer, with the "MAIL FROM" and "RCPT TO" commands. This is commonly referred to as the "envelope" of the mail, and the values usually show up in the Received: header lines.

To specify the headers you want, you have to supply them yourself before the body of the message. The smtplib example shows how that's done, in that case with a tuple called "msg" that they prepend to the message body.

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

Comments

0

One of the first gotchas I encountered with subprocess was the fact that it doesn't take full shell string commands by default.

If you want to do the equivalent of a shell command like:

os.system("echo hello world")

you need to use the shell=True option:

subprocess.Popen("echo hello world", shell=True)

1 Comment

It's not really a gotcha: well documented. It's also one of the reasons subprocess rocks. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.