Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial commit

  • Loading branch information...
commit 3e885030684f13bd60ebf1749be7cdd0c0cbb25c 0 parents
@paltman authored
2  AUTHORS
@@ -0,0 +1,2 @@
+Patrick Altman <paltman@gmail.com>
+
19 LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2011 Patrick Altman
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
3  MANIFEST.in
@@ -0,0 +1,3 @@
+include AUTHORS
+include LICENSE
+include README.rst
75 README.rst
@@ -0,0 +1,75 @@
+=======
+postman
+=======
+
+``postman`` is a simple command line working with Amazon AWS, leveraging the
+``boto`` library.
+
+
+Usage
+=====
+
+::
+
+ $ postman -h
+ usage: postman [-h] [--version] [--verbose]
+
+ {show_stats,verify,send,show_quota,delete_verified,list_verified}
+ ...
+
+ send an email via Amazon SES
+
+ positional arguments:
+ {show_stats,verify,send,show_quota,delete_verified,list_verified}
+
+ optional arguments:
+ -h, --help show this help message and exit
+ --version
+ --verbose
+
+
+Commands
+========
+
+``poastman`` has 6 different commands, in line with the various API calls available
+for Amazon SES.
+
+
+verify
+------
+
+verifies an email for sending (and in the case of the sandbox environment for
+receiving as well)
+
+
+delete_verified
+---------------
+
+removes a verified email address from your account
+
+
+list_verified
+-------------
+
+print out a list of all verified email addresses on your account
+
+
+send
+----
+
+sends an email, the content of the email is a raw email piped in very stdin, the
+only option is ``-f`` which takes a single email address that the email is sent
+from, following by 1 or more arguments that are email addresses that are the
+the destination for the email.
+
+
+show_quota
+----------
+
+print out the email quota and rate limits for you account
+
+
+show_stats
+----------
+
+print out the stats for the Amazon SES account
1  postman/__init__.py
@@ -0,0 +1 @@
+__version__ = "0.5"
124 postman/__main__.py
@@ -0,0 +1,124 @@
+import argparse
+import sys
+
+import boto
+
+from postman import __version__
+
+
+def out(msg, args):
+ if args.verbose:
+ sys.stdout.write("%s\n" % msg)
+ sys.stdout.flush()
+
+
+def cmd_send(args):
+ ses = boto.connect_ses()
+ out("Sending mail to: %s" % ", ".join(args.destinations), args)
+ msg = sys.stdin.read()
+ r = ses.send_raw_email(args.f, msg, args.destinations)
+ if r.get("SendRawEmailResponse", {}).get("SendRawEmailResult", {}).get("MessageId"):
+ out("OK", args)
+ else:
+ out("ERROR: %s" % r, args)
+
+
+def cmd_verify(args):
+ ses = boto.connect_ses()
+ for email in args.email:
+ ses.verify_email_address(email)
+ out("Verification for %s sent." % email, args)
+
+
+def cmd_list_verified(args):
+ ses = boto.connect_ses()
+ args.verbose = True
+
+ addresses = ses.list_verified_email_addresses()
+ addresses = addresses["ListVerifiedEmailAddressesResponse"]
+ addresses = addresses["ListVerifiedEmailAddressesResult"]
+ addresses = addresses["VerifiedEmailAddresses"]
+
+ if not addresses:
+ out("No addresses are verified on this account.", args)
+ return
+
+ for address in addresses:
+ out(address, args)
+
+
+def cmd_show_quota(args):
+ ses = boto.connect_ses()
+ args.verbose= True
+
+ data = ses.get_send_quota()["GetSendQuotaResponse"]["GetSendQuotaResult"]
+ out("Max 24 Hour Send: %s" % data["Max24HourSend"], args)
+ out("Sent Last 24 Hours: %s" % data["SentLast24Hours"], args)
+ out("Max Send Rate: %s" % data["MaxSendRate"], args)
+
+
+def cmd_show_stats(args):
+ ses = boto.connect_ses()
+ args.verbose = True
+
+ data = ses.get_send_statistics()
+ data = data["GetSendStatisticsResponse"]["GetSendStatisticsResult"]
+ for datum in data["SendDataPoints"]:
+ out("Complaints: %s" % datum["Complaints"], args)
+ out("Timestamp: %s" % datum["Timestamp"], args)
+ out("DeliveryAttempts: %s" % datum["DeliveryAttempts"], args)
+ out("Bounces: %s" % datum["Bounces"], args)
+ out("Rejects: %s" % datum["Rejects"], args)
+ out("", args)
+
+
+def cmd_delete_verified(args):
+ ses = boto.connect_ses()
+ for email in args.email:
+ ses.delete_verified_email_address(email_address=email)
+ out("Deleted %s" % email, args)
+
+
+def main():
+ parser = argparse.ArgumentParser(prog="postman", description="send an email via Amazon SES")
+ parser.add_argument("--version", action="version", version="%%(prog)s %s" % __version__)
+ parser.add_argument("--verbose", action="store_true")
+
+ command_parsers = parser.add_subparsers(dest="command")
+
+ # cmd: send
+ parser_send = command_parsers.add_parser("send")
+ parser_send.add_argument("-f",
+ help="the address to send the message from, must be validated")
+ parser_send.add_argument("destinations", metavar="TO", type=str, nargs="+",
+ help="a list of email addresses to deliver message to")
+
+ # cmd: verify
+ parser_send = command_parsers.add_parser("verify")
+ parser_send.add_argument("email", nargs="+",
+ help="an email address to verify for sending from")
+
+ # cmd: list_verified
+ command_parsers.add_parser("list_verified")
+
+ # cmd: show_quota
+ command_parsers.add_parser("show_quota")
+
+ # cmd: show_stats
+ command_parsers.add_parser("show_stats")
+
+ # cmd: delete_verified
+ parser_delete = command_parsers.add_parser("delete_verified")
+ parser_delete.add_argument("email", nargs="+",
+ help="verified email addresses that will be deleted from verification list")
+
+ args = parser.parse_args()
+
+ {
+ "send": cmd_send,
+ "verify": cmd_verify,
+ "list_verified": cmd_list_verified,
+ "show_quota": cmd_show_quota,
+ "show_stats": cmd_show_stats,
+ "delete_verified": cmd_delete_verified
+ }[args.command](args)
29 setup.py
@@ -0,0 +1,29 @@
+import os
+from setuptools import setup, find_packages
+
+from postman import __version__
+
+
+def read(*path):
+ return open(os.path.join(os.path.abspath(os.path.dirname(__file__)), *path)).read()
+
+
+setup(
+ name = "postman",
+ version = __version__,
+ description = "Command line for Amazon SES",
+ long_description=read("README.rst"),
+ author = "Patrick Altman",
+ author_email = "paltman@gmail.com",
+ packages = find_packages(),
+ zip_safe = False,
+ entry_points = {
+ "console_scripts": [
+ "postman = postman.__main__:main",
+ ],
+ },
+ install_requires = [
+ "argparse==1.1",
+ "boto==2.0b4"
+ ]
+)
Please sign in to comment.
Something went wrong with that request. Please try again.