惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
小众软件
小众软件
人人都是产品经理
人人都是产品经理
美团技术团队
Blog — PlanetScale
Blog — PlanetScale
S
SegmentFault 最新的问题
博客园 - 【当耐特】
V
V2EX
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 叶小钗
Google DeepMind News
Google DeepMind News
量子位
罗磊的独立博客
月光博客
月光博客
N
Netflix TechBlog - Medium
大猫的无限游戏
大猫的无限游戏
博客园_首页
P
Proofpoint News Feed
Jina AI
Jina AI
云风的 BLOG
云风的 BLOG
博客园 - 司徒正美
腾讯CDC

ashishb.net

A day in Luxembourg - the richest country in the world I was asked to install malware during a fake interview Book summary: Breakneck - China's quest to engineer the future by Dan Wang Book summary: How to Teach Your Baby to Read Book Summary: The Discontented Little Baby Book by Pamela Douglas Introducing Amazing Sandbox - run third-party tools and AI agents securely on your machine Why software outsourcing gets a bad reputation? Book summary: The Natural Baby Sleep Solution by Polly Moore A day in Antwerp, Belgium Journey of online influencers Two days in Brussels, Belgium Shortcuts - when we love them and when we don't A visit to Rakhigarhi Three days in overhyped Paris Empty Japan, crowded Tokyo The real lock-in in GitHub is not the code, but the stars 11-day Norwegian Breakaway East Caribbean cruise Sanskrit and Sri Lankan Air Force Use REST with Open API The Achilles heel of American capitalism Costa Rica in 4 days At a juice stall in Sri Lanka A short stay at Warsaw, Poland Best practices for using Python & uv inside Docker Two days in Vilnius, Lithuania How IntelliJ IDEs waste disk space Pregnancy Why there aren't many digital nomads from India Two days in Riga, Latvia To keep your machine secure, run third-party tools inside Docker
How to send HTML mails using Amazon SES (Simple Email Ser...
Ashish Bhatia · 2014-02-04 · via ashishb.net
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

import commands
import json
import logging
import sys
import tempfile

def sendEmail(mail_sender, mail_subject, mail_content, mail_receivers_list):
  """
  Args:
  mail_sender: str, sender's email address.
  mail_subject: str, subject of the email.
  mail_content: str, content (html data) of the email.
  mail_receivers_list: str, comma separated list of receivers.
  """
  # This style is specific to AWS SES.
  message_dict = { 'Data':
  'From: ' + mail_sender + '\n'
  'To: ' + mail_receivers_list + '\n'
  'Subject: ' + mail_subject + '\n'
  'MIME-Version: 1.0\n'
  'Content-Type: text/html;\n\n' +
  mail_content}
  try:
    _, message_dict_filename = tempfile.mkstemp()
    f = open(message_dict_filename,'w')
    f.write(json.dumps(message_dict))
  except IOError as e:
    logging.error(str(e))
    sys.exit(1)
  finally:
    f.close()
  aws_send_email_cmd = [
      'aws', 'ses', 'send-raw-email', '--region=us-east-1',
      '--raw-message=file://%s' % message_dict_filename]
  result = commands.getstatusoutput(' '.join(aws_send_email_cmd))
  logging.info('Sending message with subject "%s", result:%s.', mail_subject,
      result)
  if result[0] != 0:
    logging.error('Mail sending failed. Command: %s',
        ' '.join(aws_send_email_cmd))
  # It is usually a good idea to delete the file "f" at this stage.

def main():
  sendEmail('sender@gmail.com', 'mail subject', 'content of the mail',
      'foo@gmail.com, blah@gmail.com')

if __name__ == '__main__':
  main()