Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #29824
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Subject | Re: msmtp in python |
| Date | 2012-09-23 12:47 -0400 |
| Organization | > Bestiaria Support Staff < |
| References | <TPOdnevErbCBSMPNnZ2dnUVZ_hmdnZ2d@giganews.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1126.1348418872.27098.python-list@python.org> (permalink) |
On Sun, 23 Sep 2012 04:23:40 -0500, 7segment <7segment@live.com>
declaimed the following in gmane.comp.python.general:
> Hi.
>
> I have written a program to send email using python. However, I want to
> use msmtp for delegating the sending to my gmail account. So this part
> should be changed but I have no idea how! In theory the "sendmail"
> function should automatically call msmtp, but i don't know how to define
> "s" then.
>
> s = smtplib.SMTP('localhost')
From what I can make out of the msmtp documentation (less than 5
minutes of exploration), you don't.
msmtp is not an SMTP daemon process capable of receiving connections
for email. It is only an /sending/ program that connects /to/ an SMTPd
to relay email.
Classical UNIX-style email clients do not perform TCP/IP operations;
they call an external program passing it a file (or PIPE) containing the
message body (including headers), possibly with command line arguments
specifying the FROM and TO addresses. The common program is "sendmail"
msmtp is an example of that external program (with an option to
extract the addresses from the message body). It is meant to be called
instead of sendmail. See:
http://cims.nyu.edu/cgi-systems/man.cgi?section=1M&topic=sendmail
You would invoke it using (old-style) os.system() or (modern)
subprocess.Popen().
Something like
s = open("tmp-mail.file", "w")
s.write(msg.as_string())
s.close()
os.system("msmtp -t <tmp-mail.file")
{you'll need to clean up the intermediate file later, and use a random
name to avoid conflicts with other mails being queued}
or
s = subprocess.Popen(["msmtp", "-t"], stdin=subprocess.PIPE, ...)
s.communicate(msg.as_string())
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
msmtp in python 7segment <7segment@live.com> - 2012-09-23 04:23 -0500 Re: msmtp in python Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-23 12:47 -0400
csiph-web