文章内容
2024/7/1 20:16:29,作 者: 黄兵
亚马逊云科技 Amazon Simple Email Service 使用体验
我们在运营独立站的时候,用户订阅了邮件推送服务,每次发布了新的文章,我都会通过电子邮件将最新的文章推送给订阅用户,但是也带来了一个问题:那就是随着订阅人数的增加,发送邮件的费用会不断增加。
如果我们使用 Gmal 发送邮件,每天限制 500 封邮件,多了会出现:“已达到发送邮件的上限”。
这对于我们才开始,用户量很少的时候还可以用于发送营销邮件,随着用户越来越多,使用免费的 gmail 发送邮件显然是不合适的。
阿里云
腾讯云
由于疼腾讯云是按照使用量付费,所以需要我们单独计算:
5 万封邮件不需要独立 IP 价格:50000*0.0019=95 元
50 万封邮件不需要独立 IP 价格:50000*0.0019=950 元
亚马逊云科技
亚马逊云科技邮件发送服务是 Amazon SES,每个月提供 3000 封免费额度。
亚马逊 SES 计算比较复杂,这里我们还是按照 5 万封和 50 万封邮件来分别计算:
5 万封邮件不需要独立 IP,且每封邮件的大小是 32KB,价格:
- 传出邮件:(50000-3000)*0.0001 USD=4.7 USD
- 每封邮件 32KB,0.000032 GB*50000*0.12 USD=0.192 USD
- 不需要独立 IP
- 5 万封邮件总价:4.892 USD*7.27=35.56元(按照1美元兑换7.27人民币计算)
50 万封邮件不需要独立 IP,且每封邮件大大小 32 KB价格计算:
- 传出邮件:(500000-3000)*0.0001 USD=49.7 USD
- 每封邮件 32KB,0.000032 GB*500000*0.12 USD=1.92 USD
- 不需要独立 IP
- 5 万封邮件总价:51.62 USD*7.27=375.28 元(按照1美元兑换7.27人民币计算)
通过发送邮件为 5 万封价格:腾讯云 > 阿里云 > 亚马逊云科技,对于发送 50 万封邮件价格排序也是一样。
如果感觉上面计算太麻烦,我们可以直接使用亚马逊云科技的 SES 价格计算器,还是以 5 万封邮件为例,计算结果为:
这里计算的价格与上面有出入,主要是没有减去每个月 3000 封邮件的免费额度。
我们就以亚马逊云科技为例,讲解怎么配置来发送邮件推送。
这里需要说明的是:亚马逊云科技中国区不提供 Amazon Simple Email Service,只有海外区提供 Amazon Simple Email Service,按照这篇文章:亚马逊云科技中国区使用体验,注册的账号是无法体验 Amazon Simple Email Service 服务的。
Amazon Simple Email Service 使用
我们登录海外区 aws 控制台,找到所有服务:
找到企业应用程序下面的 Amazon Simple Email Service:
之后开始 Amazon Simple Email Service:
设置电子邮件地址:
这里设置的邮件地址需要您能够接收到发送到此邮件地址的邮件,后面步骤会向此邮件地址发送邮件,以验证码此地址。
设置 Mail from 域:
没有什么特殊要求,保持默认就可以了。
查看配置,没有问题就可以开始了:
验证电子邮件地址:
我们到收件箱可以看到 Amazon Simple Email Service 发送的验证邮件:
点击🔗完成邮件地址的验证:
之后发送测试邮件:
看看是否存在问题,测试完成之后配置验证发送域:
我这里使用的 CloudFlare 管理域名,直接在 DNS 增加相应记录:
这里需要注意:如果我们才开始没有配置 mail from 记录,此处需要配置 mail from 记录,配置完成之后继续将 mail from 记录的 DNS 记录填写到 CloudFlare 当中:
mail from 还有一个需要注意的地方:
红框中的 10 是优先级,不能将值全部粘贴到 DNS 记录当中,在 CloudFlare 当中的配置:
配置完成之后,开始验证发送域:
一般需要等待 2 个小时左右,当然也可能更快:
以上步骤都完成之后我们现在的账户处于沙盒模式,关于沙盒模式,官方的说法是:
为了协助防止欺诈和滥用,以及保护您作为发件人的声誉,我们在 SES 沙盒中创建了具有发送和速率限制的新账户。
也就是说:我们处在沙盒模式,会有很多限制,无法用于生产环境,关于更多详细的沙盒模式信息可以参考下面的参考资料1。
我们直接点击请求生产访问:
之后开始填写表单,具体填写要求,可以查看参考资料1,这里有详细的说明,由于在填写完成后,点击提交,此处无法截图。
提交完成之后,如果出现了问题,会告知出现问题的原因:
我们点击此 ID,需要通过工单的方式提交更多的信息。
这里提示我们:
你好,
感谢您提交增加发送限制的请求。我们希望收集更多关于您使用情况的信息。
如果您能提供更多关于您计划如何使用 Amazon SES 的信息,我们将审查这些信息,以了解您的发送方式,并推荐最佳实践以改进您的发送体验。在您的回复中,请尽可能详细地描述您的电子邮件发送过程和程序。
例如,告诉我们您发送电子邮件的频率,如何维护收件人列表,以及如何管理退信、投诉和退订请求。提供您计划发送的电子邮件示例也非常有帮助,这样我们可以确保您发送的是收件人愿意接收的高质量内容。
注意:为了发送电子邮件,您需要一个经过验证的身份,例如经过验证的电子邮件地址或域名。为了获得最佳效果,我们建议您从经过验证的域名身份开始。了解更多关于域名和电子邮件地址身份的信息:https://docs.aws.amazon.com/ses/latest/dg/creating-identities.html。
您可以通过回复此消息提供这些信息。我们的团队会在 24 小时内对您的请求作出初步回应。如果我们能够做到,我们将在 24 小时内批准您的请求。然而,我们可能需要从您那里获取更多信息,因此可能需要更长的时间来处理您的请求。
感谢您联系 Amazon Web Services。
我们需要根据内容提交相关信息,这个是我的回复模板:
您计划如何构建或获取您的邮件列表?
我们的网站底部有一个用户订阅的输入框。当用户输入他们的电子邮件地址后,我们会通过发送验证邮件来确认电子邮件地址的有效性。如果用户点击验证链接,则该电子邮件地址被视为有效的订阅用户。此外,我们严格遵守隐私政策和相关法律法规,确保用户在订阅过程中知情并同意接收我们的邮件。
您计划如何处理退信和投诉?
我们有专门的机制来处理退信和投诉。对于退信(例如无效的电子邮件地址),我们的系统会自动将这些地址从邮件列表中移除,以确保未来不会向这些地址发送邮件。对于用户的投诉,我们提供简单便捷的退订选项,用户可以通过点击邮件中的退订链接立即停止接收我们的邮件。
收件人可以如何选择不接收您的电子邮件?
每封邮件底部都有一个显著的退订链接,用户可以随时点击该链接取消订阅,退订后将不再接收我们的任何邮件。此外,我们在退订流程中也提供了用户反馈选项,以便了解用户退订的原因并改进我们的邮件内容。
您如何选择在此请求中指定的发送速率或发送配额?
我们计划每周发送一次邮件推送,邮件内容是我们网站上最新的文章。每次发送邮件时,我们会使用 Amazon SES 的 SMTP 接口,发送速率设定为每秒 1 封邮件,以确保发送过程稳定并符合 SES 的速率限制。我们预期的邮件发送量与用户订阅数量相匹配,并且我们会持续监控和调整发送策略,以确保高效和合规的邮件发送。
将上面的回复翻译成英文提交:
How do you plan to build or acquire your mailing list?
Our website has a subscription input box at the bottom. When users enter their email addresses, we send a verification email to confirm the validity of the address. If users click the verification link, the email address is considered a valid subscription. Additionally, we strictly adhere to privacy policies and relevant laws to ensure that users are informed and consent to receiving our emails during the subscription process.
How do you plan to handle bounces and complaints?
We have dedicated mechanisms to handle bounces and complaints. For bounces (e.g., invalid email addresses), our system automatically removes these addresses from the mailing list to ensure no future emails are sent to them. For user complaints, we provide a simple and convenient unsubscribe option. Users can immediately stop receiving our emails by clicking the unsubscribe link in the email.
How can recipients choose not to receive your emails?
Each email has a prominent unsubscribe link at the bottom. Users can click this link at any time to unsubscribe, and they will no longer receive any emails from us. Additionally, we provide an option for users to give feedback during the unsubscribe process to understand the reasons for unsubscribing and improve our email content.
How did you choose the sending rate or quota specified in this request?
We plan to send a weekly email containing the latest article from our website. When sending emails, we use the Amazon SES SMTP interface, setting the sending rate at 1 email per second to ensure a stable sending process and compliance with SES rate limits. Our expected email volume matches the number of subscribers, and we will continuously monitor and adjust our sending strategy to ensure efficient and compliant email delivery.
审核需要一段时间,趁着这段时间,我们配置 SMTP 发信,点击右边的 SMTP 设置菜单,完成 SMTP 设置:
之后创建 SMTP 凭证:
点击创建用户,完成 SMTP 用户的创建:
之后我们就可以使用这个用户名和密码发送邮件了。
这个是我的一个发送邮件示例代码:
# !/usr/bin/env python3 # -*- coding: utf-8 -*- import os import smtplib import ssl from email.mime.text import MIMEText from jinja2 import Environment, select_autoescape, FileSystemLoader from config import logging_config class EmailUtil(object): def __init__(self): logging_name = 'email_util' init_logging = logging_config.LoggingConfig() self._logging = init_logging.init_logging(logging_name) self._msg_from = os.environ.get('EMAIL_FROM') self._msg_password = os.environ.get('EMAIL_PASSWORD') def send_template_email(self, template, to, subj, **kwargs): get_template_path = os.path.join(os.getcwd(), 'templates') """Sends an email using a template.""" env = Environment( loader=FileSystemLoader(get_template_path), autoescape=select_autoescape(['html', 'xml']) ) template = env.get_template(template) self.send_email(to, subj, template.render(**kwargs)) def send_email(self, to, subj, body): """Sends an email.""" # 发送方邮箱 msg_from = self._msg_from # 授权码 pwd = self._msg_password # msg邮件对象 msg = MIMEText(body, 'html', 'utf-8') msg['Subject'] = subj msg['To'] = to msg['From'] = msg_from try: # 使用 gmail 邮件发送邮件代码示例:https://pdf-lib.org/Home/Details/12844 # 2022年6月18日修改,由于 gmail 限制了发送邮件的数量,使用腾讯云的邮件发送服务 # 2024 年 7 月 3 日测试 Amazon Simple Email Service # 此处代码说明:https://geekflare.com/send-gmail-in-python/ ssl_context = ssl.create_default_context() service = smtplib.SMTP_SSL('email-smtp.ap-northeast-1.amazonaws.com', 465, context=ssl_context) service.login(msg_from, pwd) service.sendmail(msg_from, to, msg.as_string()) # 发送 return True except smtplib.SMTPConnectError as e: print('邮件发送失败,连接失败:', e.smtp_code, e.smtp_error) except smtplib.SMTPAuthenticationError as e: print('邮件发送失败,认证错误:', e.smtp_code, e.smtp_error) except smtplib.SMTPSenderRefused as e: print('邮件发送失败,发件人被拒绝:', e.smtp_code, e.smtp_error) except smtplib.SMTPRecipientsRefused as e: print('邮件发送失败,收件人被拒绝:', e.smtp_code, e.smtp_error) except smtplib.SMTPDataError as e: print('邮件发送失败,数据接收拒绝:', e.smtp_code, e.smtp_error) except smtplib.SMTPException as e: print('邮件发送失败, ', str(e)) except Exception as e: print('邮件发送异常, ', str(e))
可以根据自己的需求修改。
参考资料:
评论列表