本文整理汇总了Python中boto.ses.SESConnection类的典型用法代码示例。如果您正苦于以下问题:Python SESConnection类的具体用法?Python SESConnection怎么用?Python SESConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SESConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: emit
def emit(self, record):
"""
Emit a record.
Format the record and send it to the specified addressees.
"""
client = SESConnection(self.aws_key, self.aws_secret)
message = MIMEMultipart('alternative')
message.set_charset('UTF-8')
message['Subject'] = self._encode_str(self.getSubject(record))
message['From'] = self._encode_str(self.fromaddr)
message['To'] = self._convert_to_strings(self.toaddrs)
from email.utils import formatdate
body = self.format(record)
body = "From: %s\r\n" \
"To: %s\r\n" \
"Subject: %s\r\n" \
"Date: %s\r\n\r\n" \
"%s" % (
self.fromaddr,
",".join(self.toaddrs),
self.getSubject(record),
formatdate(),
body)
message.attach(MIMEText(self._encode_str(body), 'plain'))
return client.send_raw_email(message.as_string(), self.fromaddr,
destinations=self.toaddrs)
示例2: ses_notify
def ses_notify(pricedict, stocks):
print "notify", pricedict, stocks
lines = []
keys = pricedict.keys()
keys.sort()
if stocks:
lines.append("big movers, %s" % ",".join(stocks))
for k in keys:
v = pricedict[k]
lines.append("%s : %.2f" % (k,v))
message = "\n".join(lines)
print message
import json
with open("/home/yata/keys.json") as f:
data = f.read()
keys = json.loads(data)
from boto.ses import SESConnection
connection = SESConnection(
aws_access_key_id=keys["AWS_ACCESS_KEY"],
aws_secret_access_key=keys["AWS_SECRET_KEY"]
)
connection.send_email("[email protected]",
"stock update", message,
["[email protected]", "[email protected]"],
)
示例3: send_email
def send_email(date_from, date_to, email=config['email']['default_to'], worklogs=None):
worklogs = worklogs or get_worklogs(date_from, date_to)
# put data into weeks
weeks = {}
for date in worklogs:
# add issue date
for worklog in worklogs[date]:
issue, description = get_jira_issue(worklog['task_name'])
if not issue:
worklog['issue'] = worklog['task_name']
worklog['comment'] = ''
continue
worklog['issue'] = '<a href="%s" target="_blank">%s: %s</a>' % (issue.permalink(), str(issue), issue.fields.summary)
worklog['comment'] = description
week = '%i-%02i' % (date.year, date.isocalendar()[1])
if week not in weeks:
weeks[week] = {}
weeks[week][date] = worklogs[date]
html = build_email(weeks, config['email']['template'])
connection = SESConnection(aws_access_key_id=config['email']['aws']['access_key_id'],
aws_secret_access_key=config['email']['aws']['secret_access_key'])
subject = 'Hours report %s - %s' % (date_from.strftime('%m/%d'), date_to.strftime('%m/%d'))
connection.send_email(config['email']['from'], subject, html, email, format='html')
示例4: ses_email
def ses_email(config, to_address, subject, body):
connection = SESConnection(aws_access_key_id=config['AWS_ACCESS_KEY_ID'],
aws_secret_access_key=config['AWS_SECRET_ACCESS_KEY_ID'])
from_address = '"SolutionNet" <{0}>'.format(config['FROM_EMAIL_ADDRESS'])
connection.send_email(from_address,
str(subject),
str(escape(body)),
str(to_address))
示例5: send_mail
def send_mail(msg):
global access_key
global secret_key
client = SESConnection(
aws_access_key_id=access_key, aws_secret_access_key=secret_key)
senders = msg["From"].split(",")
recipients = msg["To"].split(',')
for sender in senders:
client.send_raw_email(msg.as_string(), sender, recipients)
client.close()
示例6: send_mail_data
def send_mail_data(subject, body, format):
connection = SESConnection(aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
try:
emails = Mail.objects.all().values_list('email', flat=True)
except Mail.DoesNotExist:
emails = []
for i in range(0, len(emails), MAX_MAILS_PER_SEC):
to_addresses = emails[i:(i + MAX_MAILS_PER_SEC)]
connection.send_email(source=DEFAULT_EMAIL_SENDER, subject=subject, body=body,
to_addresses=DEFAULT_EMAIL_SENDER,
bcc_addresses=to_addresses,
format=format)
time.sleep(1)
示例7: dashboard
def dashboard(request):
"""
Graph SES send statistics over time.
"""
cache_key = 'vhash:django_ses_stats'
cached_view = cache.get(cache_key)
if cached_view:
return cached_view
region = RegionInfo(
name=getattr(settings, 'AWS_SES_REGION_NAME',
SESConnection.DefaultRegionName),
endpoint=getattr(settings, 'AWS_SES_REGION_ENDPOINT',
SESConnection.DefaultRegionEndpoint))
ses_conn = SESConnection(
aws_access_key_id=getattr(settings, 'AWS_ACCESS_KEY_ID', None),
aws_secret_access_key=getattr(settings, 'AWS_SECRET_ACCESS_KEY', None),
region=region)
quota_dict = ses_conn.get_send_quota()
verified_emails_dict = ses_conn.list_verified_email_addresses()
stats = ses_conn.get_send_statistics()
quota = quota_parse(quota_dict)
verified_emails = emails_parse(verified_emails_dict)
ordered_data = stats_to_list(stats)
summary = sum_stats(ordered_data)
extra_context = {
'title': 'SES Statistics',
'datapoints': ordered_data,
'24hour_quota': quota['Max24HourSend'],
'24hour_sent': quota['SentLast24Hours'],
'24hour_remaining': float(quota['Max24HourSend']) -
float(quota['SentLast24Hours']),
'persecond_rate': quota['MaxSendRate'],
'verified_emails': verified_emails,
'summary': summary,
'access_key': ses_conn.gs_access_key_id,
'local_time': True if pytz else False,
}
response = render_to_response(
'django_ses/send_stats.html',
extra_context,
context_instance=RequestContext(request))
cache.set(cache_key, response, 60 * 15) # Cache for 15 minutes
return response
示例8: dashboard
def dashboard(request):
"""
Graph SES send statistics over time.
"""
cache_key = 'vhash:django_ses_stats'
cached_view = cache.get(cache_key)
if cached_view:
return cached_view
region = RegionInfo(
name=settings.AWS_SES_REGION_NAME,
endpoint=settings.AWS_SES_REGION_ENDPOINT)
ses_conn = SESConnection(
aws_access_key_id=settings.ACCESS_KEY,
aws_secret_access_key=settings.SECRET_KEY,
region=region,
proxy=settings.AWS_SES_PROXY,
proxy_port=settings.AWS_SES_PROXY_PORT,
)
quota_dict = ses_conn.get_send_quota()
verified_emails_dict = ses_conn.list_verified_email_addresses()
stats = ses_conn.get_send_statistics()
quota = quota_parse(quota_dict)
verified_emails = emails_parse(verified_emails_dict)
ordered_data = stats_to_list(stats)
summary = sum_stats(ordered_data)
extra_context = {
'title': 'SES Statistics',
'datapoints': ordered_data,
'24hour_quota': quota['Max24HourSend'],
'24hour_sent': quota['SentLast24Hours'],
'24hour_remaining': float(quota['Max24HourSend']) -
float(quota['SentLast24Hours']),
'persecond_rate': quota['MaxSendRate'],
'verified_emails': verified_emails,
'summary': summary,
'access_key': ses_conn.gs_access_key_id,
'local_time': True,
}
response = render(request, 'django_ses/send_stats.html', extra_context)
cache.set(cache_key, response, 60 * 15) # Cache for 15 minutes
return response
示例9: AmazonTransport
class AmazonTransport(object):
__slots__ = ('ephemeral', 'id', 'key', 'host', 'connection')
def __init__(self, config):
self.id = config.get('id')
self.key = config.get('key')
self.host = config.get('host', "email.us-east-1.amazonaws.com")
self.connection = None
def startup(self):
self.connection = SESConnection(
aws_access_key_id = self.id,
aws_secret_access_key = self.key,
host = self.host
)
def deliver(self, message):
try:
response = self.connection.send_raw_email(
source = message.author.encode(),
destinations = message.recipients.encode(),
raw_message = str(message)
)
return (
response['SendRawEmailResponse']['SendRawEmailResult']['MessageId'],
response['SendRawEmailResponse']['ResponseMetadata']['RequestId']
)
except SESConnection.ResponseError, err:
raise # TODO: Raise appropriate internal exception.
示例10: notify_user
def notify_user(user_notification):
email = user_notification.user.email
email_body = _body(user_notification)
email_subject = _subject(user_notification)
if settings.DEBUG:
print("Sending email: {0} with subject: {1} to: {2}".format(
email_string, email_subject, email))
else:
connection = SESConnection(
aws_access_key_id=settings.AWS_ACCESS_KEY,
aws_secret_access_key=settings.AWS_SECRET_KEY)
connection.send_email(
source="[email protected]",
subject=email_subject,
body=email_body,
to_addresses=[email],
format='html',
cc_addresses=['[email protected]'])
示例11: dashboard
def dashboard(request):
"""
Graph SES send statistics over time.
"""
cache_key = "vhash:django_ses_stats"
cached_view = cache.get(cache_key)
if cached_view:
return cached_view
region = RegionInfo(name=settings.AWS_SES_REGION_NAME, endpoint=settings.AWS_SES_REGION_ENDPOINT)
ses_conn = SESConnection(
aws_access_key_id=settings.ACCESS_KEY,
aws_secret_access_key=settings.SECRET_KEY,
region=region,
boto_profile_name=settings.BOTO_PROFILE_NAME,
)
quota_dict = ses_conn.get_send_quota()
verified_emails_dict = ses_conn.list_verified_email_addresses()
stats = ses_conn.get_send_statistics()
quota = quota_parse(quota_dict)
verified_emails = emails_parse(verified_emails_dict)
ordered_data = stats_to_list(stats)
summary = sum_stats(ordered_data)
extra_context = {
"title": "SES Statistics",
"datapoints": ordered_data,
"24hour_quota": quota["Max24HourSend"],
"24hour_sent": quota["SentLast24Hours"],
"24hour_remaining": float(quota["Max24HourSend"]) - float(quota["SentLast24Hours"]),
"persecond_rate": quota["MaxSendRate"],
"verified_emails": verified_emails,
"summary": summary,
"access_key": ses_conn.gs_access_key_id,
"local_time": True if pytz else False,
}
response = render_to_response("django_ses/send_stats.html", extra_context, context_instance=RequestContext(request))
cache.set(cache_key, response, 60 * 15) # Cache for 15 minutes
return response
示例12: _send_email
def _send_email(email, amount, confirm_code):
if not settings.DEBUG:
context = {
'confirm_url': 'http://{0}{1}'.format(
Site.objects.get_current().domain,
reverse('main:confirm_pledge', args=[confirm_code])) }
connection = SESConnection(
aws_access_key_id=settings.AWS_ACCESS_KEY,
aws_secret_access_key=settings.AWS_SECRET_KEY)
connection.send_email(
source="[email protected]",
subject="Please confirm your pledge",
body=render_to_string('pledge_email.html', context),
to_addresses=[email],
format='html',
cc_addresses=['[email protected]'])
else:
print('Sent email to {0} about {1} with confirm code {2}'.format(
email, amount, confirm_code))
示例13: handle_noargs
def handle_noargs(self, **options):
subject = 'hi krista'
fromName = 'krista'
fromAddress = '[email protected]'
toAddressesStr = '[email protected]'
textBody = 'hihihi'
htmlBody = 'body yo yo yo'
Charset.add_charset('utf-8', Charset.QP, Charset.QP, 'utf-8')
msg = MIMEMultipart('alternative')
msg['Subject'] = subject
msg['From'] = "" + str(fromName) + " <" + fromAddress + ">"
msg['To'] = toAddressesStr
connection = SESConnection(aws_access_key_id=settings.AWS_ACCESS_KEY,
aws_secret_access_key=settings.AWS_SECRET_KEY)
connection.send_email(fromName + " <" + fromAddress + ">",
subject, body=htmlBody,
to_addresses=toAddressesStr, text_body=textBody,
format="html", return_path=fromAddress)
示例14: handle
def handle(self, *args, **options):
connection = SESConnection(
aws_access_key_id=settings.ACCESS_KEY,
aws_secret_access_key=settings.SECRET_KEY,
proxy=settings.AWS_SES_PROXY,
proxy_port=settings.AWS_SES_PROXY_PORT,
proxy_user=settings.AWS_SES_PROXY_USER,
proxy_pass=settings.AWS_SES_PROXY_PASS,
)
stats = connection.get_send_statistics()
data_points = stats_to_list(stats, localize=False)
stats_dict = defaultdict(stat_factory)
for data in data_points:
attempts = int(data['DeliveryAttempts'])
bounces = int(data['Bounces'])
complaints = int(data['Complaints'])
rejects = int(data['Rejects'])
date = data['Timestamp'].split('T')[0]
stats_dict[date]['delivery_attempts'] += attempts
stats_dict[date]['bounces'] += bounces
stats_dict[date]['complaints'] += complaints
stats_dict[date]['rejects'] += rejects
for k, v in stats_dict.items():
stat, created = SESStat.objects.get_or_create(
date=k,
defaults={
'delivery_attempts': v['delivery_attempts'],
'bounces': v['bounces'],
'complaints': v['complaints'],
'rejects': v['rejects'],
})
# If statistic is not new, modify data if values are different
if not created and stat.delivery_attempts != v['delivery_attempts']:
stat.delivery_attempts = v['delivery_attempts']
stat.bounces = v['bounces']
stat.complaints = v['complaints']
stat.rejects = v['rejects']
stat.save()
示例15: handle
def handle(self, *args, **options):
verbosity = options.get('verbosity', 0)
add_email = options.get('add', False)
delete_email = options.get('delete', False)
list_emails = options.get('list', False)
access_key_id = settings.ACCESS_KEY
access_key = settings.SECRET_KEY
region = RegionInfo(
name=settings.AWS_SES_REGION_NAME,
endpoint=settings.AWS_SES_REGION_ENDPOINT)
connection = SESConnection(
aws_access_key_id=access_key_id,
aws_secret_access_key=access_key,
region=region)
if add_email:
if verbosity != '0':
print "Adding email: %s" % add_email
connection.verify_email_address(add_email)
elif delete_email:
if verbosity != '0':
print "Removing email: %s" % delete_email
connection.delete_verified_email_address(delete_email)
elif list_emails:
if verbosity != '0':
print "Fetching list of verified emails:"
response = connection.list_verified_email_addresses()
emails = response['ListVerifiedEmailAddressesResponse'][
'ListVerifiedEmailAddressesResult']['VerifiedEmailAddresses']
for email in emails:
print email