You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2006/03/30 05:07:42 UTC
svn commit: r389975 - in /james/server/trunk/src/python: ./ sendmail.py
Author: noel
Date: Wed Mar 29 19:07:41 2006
New Revision: 389975
URL: http://svn.apache.org/viewcvs?rev=389975&view=rev
Log:
Add a simple "sendmail" client for use on *nix systems for when JAMES is the (only) MTA installed.
Added:
james/server/trunk/src/python/
james/server/trunk/src/python/sendmail.py (with props)
Added: james/server/trunk/src/python/sendmail.py
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/python/sendmail.py?rev=389975&view=auto
==============================================================================
--- james/server/trunk/src/python/sendmail.py (added)
+++ james/server/trunk/src/python/sendmail.py Wed Mar 29 19:07:41 2006
@@ -0,0 +1,123 @@
+#!/usr/bin/python
+#
+# Copyright 2006 The Apache Software Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# --------------------------------------------------------------------------
+#
+# This is a simple mail client intended to suffice as the required
+# "sendmail" client on typical UNIX-style systems. It requires an
+# SMTP SMTP server for handling the e-mail that users and system
+# utilities may send via "sendmail".
+#
+# To install, symlink from /usr/{[s]bin,lib[exec]}/sendmail or similar
+# for the particular deployment.
+#
+# --------------------------------------------------------------------------
+
+
+import smtplib
+import socket
+import os
+import sys
+import getopt
+
+
+def Usage():
+ print "sendmail [-f <from_addr>][-F <full name>][-t][-h]"
+ sys.exit(0)
+
+
+def ProcessHeaders(headers, to_addrs, extract, fullname, from_addr):
+ hasFrom = False
+ for header in headers:
+ if header.startswith("To:"):
+ if extract:
+ to = header[3:]
+ to_addrs.append(to[("<" + to).rfind("<"):(to + ">").find(">")])
+ elif header.startswith("From:"):
+ hasFrom = True
+
+ if hasFrom:
+ header = "Sender"
+ else:
+ header = "From"
+
+ if fullname:
+ headers.insert(0, "%s: %s <%s>" % (header,fullname, from_addr))
+ else:
+ headers.insert(0, "%s: %s" % (header, from_addr))
+
+ return headers, to_addrs
+
+
+def main(argv):
+ try:
+ optlist, list = getopt.getopt(sys.argv[1:], 'f:F:ht')
+ except getopt.GetoptError:
+ Usage()
+ print >> sys.stderr, "called exception"
+ sys.exit(2)
+
+ to_addrs = list
+ from_addr = os.environ['USER'] + '@' + socket.getfqdn()
+
+ fullname = ""
+ extract = False
+
+ for opt, value in optlist:
+ if opt == '-h':
+ Usage()
+ elif opt == '-t':
+ extract = True
+ elif opt == '-F':
+ fullname = value
+ elif opt == '-f':
+ from_addr = value
+
+ print "Enter message, end with ^D (Unix) or ^Z (Windows):"
+
+ processedHeaders = False
+ msg = []
+
+ while 1:
+ try:
+ line = raw_input()
+ except EOFError:
+ break
+ if not line and not processedHeaders:
+ msg, to_addrs = ProcessHeaders(msg, to_addrs, extract, fullname, from_addr)
+ processedHeaders = True
+ msg.append(line)
+
+ msg = "\r\n".join(msg)
+
+# print "MAIL FROM: " + from_addr
+# print "RCPT TO: " + ", ".join(to_addrs)
+# print msg
+
+ if not to_addrs:
+ print >> sys.stderr, "Must specify recipients on command line, or use -t with To: headers in message"
+ sys.exit(0)
+
+# sys.exit(0)
+
+ server = smtplib.SMTP('localhost')
+ server.set_debuglevel(0)
+ server.sendmail(from_addr, to_addrs, msg)
+ server.quit()
+
+
+if __name__ == '__main__':
+ main(sys.argv)
Propchange: james/server/trunk/src/python/sendmail.py
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org