Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #29801 > unrolled thread

msmtp in python

Started by7segment <7segment@live.com>
First post2012-09-23 04:23 -0500
Last post2012-09-23 12:47 -0400
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  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

#29801 — msmtp in python

From7segment <7segment@live.com>
Date2012-09-23 04:23 -0500
Subjectmsmtp in python
Message-ID<TPOdnevErbCBSMPNnZ2dnUVZ_hmdnZ2d@giganews.com>
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')
s.sendmail(me, family, msg.as_string())
s.quit()

Any help would be appreciated!

[toc] | [next] | [standalone]


#29824

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2012-09-23 12:47 -0400
Message-ID<mailman.1126.1348418872.27098.python-list@python.org>
In reply to#29801
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/

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web