I am trying to send raw email using ses and getting error result = conn.send_raw_email(msg.as_string(), AttributeError: 'NoneType' object has no attribute 'send_raw_email', Can you please take look? Thanks a lot.
import boto.ses
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
def send_ses():
to_emails = ['contact.ranvijay@gmail.com']
COMMASPACE = ', '
msg = MIMEMultipart()
msg['Subject'] = 'test'
msg['From'] = 'contact.ranvijay@gmail.com'
msg['To'] = COMMASPACE.join(to_emails)
# msg.attach(MIMEText(body))
filename = '/Users/Mac/test/products/error_csv/price_upload_error_2016-05-10 19:50:06.868506.csv'
attachment = open(filename, 'rb').read()
part = MIMEApplication(attachment)
part.add_header('Content-Disposition', 'attachment', filename='test.csv')
msg.attach(part)
try:
conn = boto.ses.connect_to_region(
'US-EAST-1',
aws_access_key_id=AWS_ACCESS_KEY,
aws_secret_access_key=AWS_SECRET_KEY
)
except Exception as e:
return e.__str__()
result = conn.send_raw_email(msg.as_string(),
source=msg['From'],
destinations=to_emails
)
return result if 'ErrorResponse' in result else ''
if __name__ == '__main__':
send_ses()
You call conn.send_raw_email
and get a response that you are trying to access the .send_raw_email of a NoneType. Therefore, conn == None
. You should check for that. The docs for boto.ses.connect_to_region say it returns None if you give an invalid region name. From this list of regions it looks like your problem is your region name should be in lower case instead of upper.