Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!transit4.readnews.com!panix!not-for-mail From: Grant Edwards Newsgroups: comp.lang.python Subject: Re: sendmail library ?! Date: Mon, 18 Nov 2013 17:56:14 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 39 Message-ID: References: NNTP-Posting-Host: dsl.comtrol.com X-Trace: reader1.panix.com 1384797374 1809 64.122.56.22 (18 Nov 2013 17:56:14 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Mon, 18 Nov 2013 17:56:14 +0000 (UTC) User-Agent: slrn/1.0.1 (Linux) Xref: csiph.com comp.lang.python:59897 On 2013-11-18, Tim Roberts wrote: > Tamer Higazi wrote: >> >>I am looking for a python library that does mailing directly through >>"sendmail". >> >>When I look into the docs, I see only an "smtlip" library but nothing >>that could serve with sendmail or postfix. >> >>Any ideas ?! > > Remember that > import smtplib > s = smtplib.SMTP("localhost") > usually communicates directly with the local server, whether it be sendmail > or postfix or whatever. It's not uncommon for a machine that doesn't receive mail to have sendmail/postfix/whatever installed for the purpose of sending mail only. In that case, there might not be anybody listening on (localhost,smtp). The traditional way to send mail on a Unix system is to invoke the 'sendmail' command with appropriate command-line arguments and then shove the message into sendmail's stdin. It's pretty trivial -- here's a simple "sendmail library": def sendmail(frm,to,msg): with os.popen("sendmail -f '%s' '%s'" % (frm,to), "w") as p: p.write(msg) That works on my system, but YMMV. You might like more options (like automagically parsing frm/to address from msg headers or whatnot), and those are left as an exercise for the reader. -- Grant Edwards grant.b.edwards Yow! Did an Italian CRANE at OPERATOR just experience gmail.com uninhibited sensations in a MALIBU HOT TUB?