sendmail library ?!

T

Tamer Higazi

Hi people!

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 ?!

Thanks....


Tamer
 
T

Tim Roberts

Tamer Higazi said:
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.
 
G

Grant Edwards

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top