Skip to content

Commit 4842907

Browse files
committed
Added send_email method to manager.
1 parent ddfbe1d commit 4842907

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/aws.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from ConfigParser import SafeConfigParser
2+
from email.mime.text import MIMEText
23
import os
4+
from boto import ses
35
import boto.ec2
46
import time
57
from boto.ec2.address import Address
@@ -74,6 +76,18 @@ def launch_new_instance(self, name, image_id=None, instance_type=None, placement
7476

7577
return instance
7678

79+
def send_email(self, fromaddr, recipient, subject, body):
80+
msg = MIMEText(body)
81+
msg['Subject'] = subject
82+
msg['From'] = fromaddr
83+
msg['To'] = recipient
84+
85+
aws_access_key_id = self._cfg['aws_access_key_id']
86+
aws_secret_access_key = self._cfg['aws_secret_access_key']
87+
conn = ses.connect_to_region(self._cfg['region'], aws_access_key_id=aws_access_key_id,
88+
aws_secret_access_key=aws_secret_access_key)
89+
conn.send_raw_email(msg.as_string())
90+
7791
def start_instance_by_name(self, name, wait=True):
7892
prev_only_running = self.only_running
7993
self.only_running = False

src/test_aws.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,12 @@ def test_name_must_be_unique(self):
9797
i2.terminate()
9898
except UnboundLocalError:
9999
pass
100+
101+
def test_send_email(self):
102+
raise unittest.SkipTest('development only')
103+
fromaddr = '[email protected]'
104+
recipient = '[email protected]'
105+
subject = 'OCGIS_AWS'
106+
body = 'This is some email content.'
107+
m = AwsManager(CONF_PATH)
108+
m.send_email(fromaddr, recipient, subject, body)

0 commit comments

Comments
 (0)