Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'intermediate': 0.05; 'arguments': 0.07; 'see:': 0.07; '"w")': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'sep': 0.09; 'specifying': 0.09; 'tcp/ip': 0.09; 'subject:python': 0.11; 'passing': 0.15; '"s"': 0.16; 'delegating': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 's.close()': 0.16; 'smtpd': 0.16; 'unix-style': 0.16; 'url:edu': 0.18; '(or': 0.18; 'define': 0.20; 'written': 0.20; 'meant': 0.21; 'example': 0.23; 'random': 0.24; 'idea': 0.24; 'external': 0.24; 'command': 0.24; 'common': 0.26; 'possibly': 0.27; 'connects': 0.27; 'then.': 0.27; 'header:X-Complaints-To:1': 0.28; 'invoke': 0.29; '(including': 0.30; 'connections': 0.30; 'function': 0.30; 'file': 0.32; 'addresses': 0.32; 'skip:s 30': 0.33; 'extract': 0.33; 'url:home': 0.33; 'to:addr:python-list': 0.33; '(with': 0.33; 'changed': 0.34; 'smtp': 0.35; 'something': 0.35; 'received:org': 0.36; 'but': 0.36; 'should': 0.36; 'charset:us- ascii': 0.36; 'option': 0.37; 'being': 0.37; 'subject:: ': 0.38; 'perform': 0.38; 'skip:o 20': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'called': 0.39; 'header:Received:5': 0.40; 'containing': 0.61; 'capable': 0.63; 'url:cgi': 0.65; 'account.': 0.83; 'url:topic': 0.84; 'mails': 0.88; 'dennis': 0.91; 'received:108': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: msmtp in python Date: Sun, 23 Sep 2012 12:47:53 -0400 Organization: > Bestiaria Support Staff < References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-108-79-217-201.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 3.3/32.846 X-No-Archive: YES X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348418872 news.xs4all.nl 6867 [2001:888:2000:d::a6]:46360 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29824 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