Exemplo n.º 1
0
def send_mail(mail_address, mail_title, mail_text):
    conn = SESConnection()
    to_addresses = [mail_address]
    # SendMail APIを呼び出す
    conn.send_email(
        '*****@*****.**'  # 送信元アドレス
        ,
        mail_title  # メールの件名
        ,
        mail_text  # メールの本文
        ,
        to_addresses  # 送信先のアドレスリスト 
    )
Exemplo n.º 2
0
class AmazonSESMailer(BaseMailer):
    """A mailer for Amazon Simple Email Server.
    Requires the `boto` python library.
    """

    def __init__(self, aws_access_key_id, aws_secret_access_key,
                 return_path=None, *args, **kwargs):
        """
        """
        from boto.ses.connection import SESConnection

        self.conn = SESConnection(
            aws_access_key_id=aws_access_key_id,
            aws_secret_access_key=aws_secret_access_key
        )
        assert self.conn
        self.return_path = return_path
        super(AmazonSESMailer, self).__init__(*args, **kwargs)

    def send_messages(self, *email_messages):
        """
        """
        logger = logging.getLogger('mailshake:AmazonSESMailer')
        if not email_messages:
            logger.debug('No email messages to send')
            return

        for msg in email_messages:
            data = {
                'source': msg.from_email,
                'subject': msg.subject,
                'body': msg.html or msg.text,
                'to_addresses': msg.to,

                'cc_addresses': msg.cc or None,
                'bcc_addresses': msg.bcc or None,
                'reply_addresses': msg.reply_to or None,
                'format': 'html' if msg.html else 'text',
            }
            if self.return_path:
                data['return_path'] = self.return_path
            logger.debug('Sending email from {0} to {1}'.format(msg.from_email, msg.to))
            self.conn.send_email(**data)
def test_send_emails(vars):
    aws_key = 'YOUR_AWS_KEY'
    aws_secret_key = 'YOUR_SECRET_KEY'
    from boto.ses.connection import SESConnection
    conn = SESConnection(aws_key, aws_secret_key)
    return conn.send_email(source=vars.source,
                           subject=vars.subject, 
                           body=vars.body,
                           to_addresses=vars.to_addresses,
                           cc_addresses=vars.cc_addresses,
                           bcc_addresses=vars.bcc_addresses,
                           format=vars.format,
                           reply_addresses=vars.reply_addresses,
                           return_path=vars.return_path)
class EmailProcessor(object):

    def __init__(self):
        self.con = SESConnection()

    def send_success(self, to, id):
        msg = """Hello! This is an automated email from Sentimentron.

Sentimentron's finished processing your request and has produced some results. 
To view them, copy the following into your browser:

    <ul style="list-style-type:none"><li><a href="http://results.sentimentron.co.uk/index.html#%d">http://results.sentimentron.co.uk/index.html#%d</a></li></ul>

Hope you find the results useful! If you have any questions or feedback, please email <a href="mailto:[email protected]">[email protected]</a>.""" % (id, id)
    
        self.con.send_email("*****@*****.**", 
            "Good news from Sentimentron",
            msg + FOOTER,
            [to], None, None, 'html'
        )

    def send_failure(self, to, error):
        msg = """Hello! This is an automated email from Sentimentron.

Unfortunately, Sentimentron encountered a problem processing your query and
hasn't produced any results. Apologies for the inconvenience. The problem was:

    <ul style="list-style-type:none; font-weight:bold"><li>%s</li></ul>

If you have any questions or feedback, please email <a href="mailto:[email protected]">[email protected]</a>.""" % (error,)

        self.con.send_email('*****@*****.**', 
            'Bad news from Sentimentron',
            msg + FOOTER,
            [to], None, None, 'html'
        )
Exemplo n.º 5
0
class SESConnectionTest (unittest.TestCase):
    
    def get_suite_description(self):
        return 'SES connection test suite'

    def setUp(self):
        self.conn = SESConnection()
        self.test_email = '*****@*****.**'
    
    def test_1_connection(self):
        """ Tests insantiating basic connection """
        
        c = SESConnection()
        assert c
    
    def test_2_get_send_statistics(self):
        """ Tests retrieving send statistics """
        
        assert self.conn.get_send_statistics()
        
    def test_3_get_send_quota(self):
        """ Tests retrieving send quota """
        
        assert self.conn.get_send_quota()
        
    def test_4_get_verified_emails(self):
        """ Tests retrieving list of verified emails """
        
        assert self.conn.get_verified_emails()
        
    def test_5_verify_email_address(self):
        """ Tests verifying email address """
        
        assert self.conn.verify_email_address(email=self.test_email)
    
    def test_6_send_email(self):
        """ Tests sending an email """
        
        assert self.conn.send_email(source=self.test_email,
                     subject='Test',
                     message='Test Message',
                     to='self.test_email')
        
        # Email with cc and bcc
        assert self.conn.send_email(source=self.test_email, 
                         subject='Test', 
                         message='Test Message', 
                         to=[self.test_email], 
                         cc=[self.test_email],
                         bcc=[self.test_email])
                        
    def test_7_send_raw_email(self):
        """ Tests sending a raw email """
        
        assert self.conn.send_raw_email(source=self.test_email,
                         message=self._create_raw_email_message())
    def test_8_delete_verified_email(self):
        """ Tests deleting verified email """
        
        assert self.conn.delete_verified_email(email=self.test_email)
        
    def _create_raw_email_message(self):
        """ Creates a test mime-type email using native Email class """
        
        me = self.test_email
        you = self.test_email

        # Create message container - the correct MIME type is multipart/alternative.
        msg = MIMEMultipart('alternative')
        msg['From'] = me
        msg['To'] = you
        msg['Subject'] = "Link"

        # Create the body of the message (a plain-text and an HTML version).
        text = "Hi!\nHow are you?\nHere is the link you wanted:\nhttp://www.python.org"
        html = """\
        <html>
          <head></head>
          <body>
            <p>Hi!<br>
               How are you?<br>
               Here is the <a href="http://www.python.org">link</a> you wanted.
            </p>
          </body>
        </html>
        """

        # Record the MIME types of both parts - text/plain and text/html.
        part1 = MIMEText(text, 'plain')
        part2 = MIMEText(html, 'html')

        # Attach parts into message container.
        # According to RFC 2046, the last part of a multipart message, in this case
        # the HTML message, is best and preferred.
        msg.attach(part1)
        msg.attach(part2)
    
        return msg
Exemplo n.º 6
0
def send_email(subject, body):
    connection = SESConnection(aws_access_key_id=AWS_ACCESS_KEY_ID,
                               aws_secret_access_key=AWS_SECRET_ACCESS_KEY)

    connection.send_email(FROM_EMAIL, subject, body, TO_EMAIL)
Exemplo n.º 7
0
	def emit(self,record):
		conn = SESConnection(AWS_ACCESS_KEY,AWS_SECRET_ACCESS_KEY)
		conn.send_email(self.fromaddr,self.subject,self.format(record),self.toaddrs)
Exemplo n.º 8
0
 def send(self):
     connection = SESConnection(self.app.config['AWS_ACCESS_KEY'],
                                self.app.config['AWS_SECRET'])
     connection.send_email(self.sender, self.subject, self.body, 
                           self.recipient)
Exemplo n.º 9
0
 def emit(self, record):
     conn = SESConnection(self.aws_access_key_id,
                          self.aws_secret_access_key)
     conn.send_email(self.fromaddr, self.subject, self.format(record),
                     self.toaddrs)
Exemplo n.º 10
0
def SendEmail(to,subject,message,from_addr="*****@*****.**",format="html"):
	conn = SESConnection(AWS_ACCESS_KEY,AWS_SECRET_ACCESS_KEY)
	conn.send_email(from_addr,subject,message,to,format=format)
Exemplo n.º 11
0
	def emit(self,record):
		conn = SESConnection(AWS_ACCESS_KEY,AWS_SECRET_ACCESS_KEY)
		conn.send_email(self.fromaddr,self.subject,self.format(record),self.toaddrs)
Exemplo n.º 12
0
if __name__ == '__main__':
    return_code = 'unknown'
    host = socket.getfqdn()
    wal_file = 'unknown'
    try:
        ses_conn = SESConnection()
        wal_file = sys.argv[1]
        wal_push = '/usr/local/bin/wal-e'
        return_code = subprocess.call([wal_push, 'wal-push', wal_file])
    except Exception, e:
        return_code = str(e)
    finally:
        if return_code != 0:
            if os.path.exists(TMPFILE):
                contents = open(TMPFILE).read()
                last_wal_error = contents
                if wal_file == last_wal_error:
                    ses_conn.send_email(source='youremail@',
                                        subject='PG WAL Archive Failed!',
                                        body='Host: %s\nError: %s\nWAL: %s' %
                                        (host, return_code, wal_file),
                                        to_addresses=['toemail@'])
                    sys.exit(1)
            outfl = open(TMPFILE, 'w')
            outfl.write(wal_file)
            outfl.close()
            sys.exit(1)
        else:
            if os.path.exists(TMPFILE):
                os.remove(TMPFILE)
            sys.exit(0)