PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/boto-2.5.2/docs/source/ses_tut.rst

#
ReStructuredText | 171 lines | 141 code | 30 blank | 0 comment | 0 complexity | 301b088d5c6c45f78203283b1c7dc5ae MD5 | raw file
  1. .. ses_tut:
  2. =============================
  3. Simple Email Service Tutorial
  4. =============================
  5. This tutorial focuses on the boto interface to AWS' `Simple Email Service (SES) <ses>`_.
  6. This tutorial assumes that you have boto already downloaded and installed.
  7. .. _SES: http://aws.amazon.com/ses/
  8. Creating a Connection
  9. ---------------------
  10. The first step in accessing SES is to create a connection to the service.
  11. To do so, the most straight forward way is the following::
  12. >>> import boto
  13. >>> conn = boto.connect_ses(
  14. aws_access_key_id='<YOUR_AWS_KEY_ID>',
  15. aws_secret_access_key='<YOUR_AWS_SECRET_KEY>')
  16. >>> conn
  17. SESConnection:email.us-east-1.amazonaws.com
  18. Bear in mind that if you have your credentials in boto config in your home
  19. directory, the two keyword arguments in the call above are not needed. More
  20. details on configuration can be fond in :doc:`boto_config_tut`.
  21. The :py:func:`boto.connect_ses` functions returns a
  22. :py:class:`boto.ses.connection.SESConnection` instance, which is a the boto API
  23. for working with SES.
  24. Notes on Sending
  25. ----------------
  26. It is important to keep in mind that while emails appear to come "from" the
  27. address that you specify via Reply-To, the sending is done through Amazon.
  28. Some clients do pick up on this disparity, and leave a note on emails.
  29. Verifying a Sender Email Address
  30. --------------------------------
  31. Before you can send email "from" an address, you must prove that you have
  32. access to the account. When you send a validation request, an email is sent
  33. to the address with a link in it. Clicking on the link validates the address
  34. and adds it to your SES account. Here's how to send the validation email::
  35. >>> conn.verify_email_address('some@address.com')
  36. {
  37. 'VerifyEmailAddressResponse': {
  38. 'ResponseMetadata': {
  39. 'RequestId': '4a974fd5-56c2-11e1-ad4c-c1f08c91d554'
  40. }
  41. }
  42. }
  43. After a short amount of time, you'll find an email with the validation
  44. link inside. Click it, and this address may be used to send emails.
  45. Listing Verified Addresses
  46. --------------------------
  47. If you'd like to list the addresses that are currently verified on your
  48. SES account, use
  49. :py:meth:`list_verified_email_addresses <boto.ses.connection.SESConnection.list_verified_email_addresses>`::
  50. >>> conn.list_verified_email_addresses()
  51. {
  52. 'ListVerifiedEmailAddressesResponse': {
  53. 'ListVerifiedEmailAddressesResult': {
  54. 'VerifiedEmailAddresses': [
  55. 'some@address.com',
  56. 'another@address.com'
  57. ]
  58. },
  59. 'ResponseMetadata': {
  60. 'RequestId': '2ab45c18-56c3-11e1-be66-ffd2a4549d70'
  61. }
  62. }
  63. }
  64. Deleting a Verified Address
  65. ---------------------------
  66. In the event that you'd like to remove an email address from your account,
  67. use
  68. :py:meth:`delete_verified_email_address <boto.ses.connection.SESConnection.delete_verified_email_address>`::
  69. >>> conn.delete_verified_email_address('another@address.com')
  70. Sending an Email
  71. ----------------
  72. Sending an email is done via
  73. :py:meth:`send_email <boto.ses.connection.SESConnection.send_email>`::
  74. >>> conn.send_email(
  75. 'some@address.com',
  76. 'Your subject',
  77. 'Body here',
  78. ['recipient-address-1@gmail.com'])
  79. {
  80. 'SendEmailResponse': {
  81. 'ResponseMetadata': {
  82. 'RequestId': '4743c2b7-56c3-11e1-bccd-c99bd68002fd'
  83. },
  84. 'SendEmailResult': {
  85. 'MessageId': '000001357a177192-7b894025-147a-4705-8455-7c880b0c8270-000000'
  86. }
  87. }
  88. }
  89. If you're wanting to send a multipart MIME email, see the reference for
  90. :py:meth:`send_raw_email <boto.ses.connection.SESConnection.send_raw_email>`,
  91. which is a bit more of a low-level alternative.
  92. Checking your Send Quota
  93. ------------------------
  94. Staying within your quota is critical, since the upper limit is a hard cap.
  95. Once you have hit your quota, no further email may be sent until enough
  96. time elapses to where your 24 hour email count (rolling continuously) is
  97. within acceptable ranges. Use
  98. :py:meth:`get_send_quota <boto.ses.connection.SESConnection.get_send_quota>`::
  99. >>> conn.get_send_quota()
  100. {
  101. 'GetSendQuotaResponse': {
  102. 'GetSendQuotaResult': {
  103. 'Max24HourSend': '100000.0',
  104. 'SentLast24Hours': '181.0',
  105. 'MaxSendRate': '28.0'
  106. },
  107. 'ResponseMetadata': {
  108. 'RequestId': u'8a629245-56c4-11e1-9c53-9d5f4d2cc8d3'
  109. }
  110. }
  111. }
  112. Checking your Send Statistics
  113. -----------------------------
  114. In order to fight spammers and ensure quality mail is being sent from SES,
  115. Amazon tracks bounces, rejections, and complaints. This is done via
  116. :py:meth:`get_send_statistics <boto.ses.connection.SESConnection.get_send_statistics>`.
  117. Please be warned that the output is extremely verbose, to the point
  118. where we'll just show a short excerpt here::
  119. >>> conn.get_send_statistics()
  120. {
  121. 'GetSendStatisticsResponse': {
  122. 'GetSendStatisticsResult': {
  123. 'SendDataPoints': [
  124. {
  125. 'Complaints': '0',
  126. 'Timestamp': '2012-02-13T05:02:00Z',
  127. 'DeliveryAttempts': '8',
  128. 'Bounces': '0',
  129. 'Rejects': '0'
  130. },
  131. {
  132. 'Complaints': '0',
  133. 'Timestamp': '2012-02-13T05:17:00Z',
  134. 'DeliveryAttempts': '12',
  135. 'Bounces': '0',
  136. 'Rejects': '0'
  137. }
  138. ]
  139. }
  140. }
  141. }