TOPNEC

甲骨文免费域名邮箱

介绍

前一段时间运气不错,成功注册了甲骨文云的账号,发现甲骨文云的 Free Tire 里有一项免费邮件发送服务 Oracle Email Delivery,这个类似于 Amazon 家的 SES,我参考了网上一个叫兔哥的博客的攻略做了配置,这里简单介绍下:

配置的过程很简单,可以全程参考这个教程:甲骨文云免费电子邮件服务-5分钟轻松设置 - 兔哥博客,我这里总结下我在配置中的关键点和问题:

创建邮件域

菜单-开发人员服务-电子邮件传送-电子邮件域:创建电子邮件域,比如 mydomian.org ,直接创建。

配置DKIM

添加 DKIM-创建 DKIM ,输入一个前缀比如 mydkim ,生成,并将生成的 CNAME 信息 添加到 域名的DNS 管理后台,然后点击 「创建 DKIM」,稍等片刻,刷新页面,确认变为绿色图标的 Active 状态

配置SPF

添加 SPF “v=spf1 include:rp.oracleemaildelivery.com include:ap.rp.oracleemaildelivery.com include:eu.rp.oracleemaildelivery.com ~all” 在 域名 DNS 管理后台 将上述信息作为 TXT 记录添加,稍等片刻,刷新页面,确认变为绿色图标的 Active 状态;如果你的域名的 DNS 配置里已经有了 SPF,比如我之前配置了 Cloudflare Email Routing 是就已经配置了 SPF,那么只需要在这条记录里追加即可,比如我这种情况,最终该txt记录内容是这样:

"v=spf1 include:_spf.mx.cloudflare.net include:rp.oracleemaildelivery.com include:ap.rp.oracleemaildelivery.com include:eu.rp.oracleemaildelivery.com ~all"

配置返回路径(可选)

按步骤创建定制返回路径,并将生成的 CNAME 信息 添加到 域名的DNS 管理后台,稍等片刻,刷新页面,确认变为绿色图标的 Active 状态;这一步可以支持退信,使得该域名邮箱的信用度更高减少被”垃圾“邮件的可能性。

注意:这一步不是必须的,但不设置会导致收信后看到的邮件发送域是一个 Oracle 的域名,这不仅看上去不那么友好,并且这在 SPF 的 对齐检查 项目中会失败( SPF 对齐检查要求邮件的 From: domian 要和 MailFrom / Return Path domain 完全相同,或者至少是父子域关系)

批准的发件人

菜单-电子邮件传送-批准的发件人,至少创建一个发件人邮箱地址,比如: [email protected] ,这样做可以保证 SMTP 服务只能以这个邮件地址作为发件人发信

创建 SMTP 身份证明

右上角头像-我的概要信息-SMTP 身份证明,生成身份证明,将用户名和密码记录下来(这里只显示一次)。这一步自动生成的用户名非常的长,也很可能是这个原因导致了后续无法在 Gmail 中配置成功

设置发送服务

菜单-电子邮件传送-配置,记录 SMTP 的公共端点以及端口,配合上面步骤生成的身份证明的用户名密码,就可以在第三方服务里配置发送服务了。最简单方式,就是用 Python 发一封信试一试(记得修改里面的配置为上面你设置的配置信息):

# python script for sending SMTP configuration with Oracle Cloud Infrastructure Email Delivery
import smtplib 
import email.utils
from email.message import EmailMessage
import ssl

# Replace [email protected] with your "From" address.
# This address must be verified.
# this is the approved sender email
SENDER = '[email protected]'
SENDERNAME = 'Sender Name'
 
# Replace [email protected] with a "To" address. If your account
# is still in the sandbox, this address must be verified.
RECIPIENT = '[email protected]'
 
# Replace the USERNAME_SMTP value with your Email Delivery SMTP username.
USERNAME_SMTP = 'ocid1.user.oc1..<unique_ID>@ocid1.tenancy.oc1..<unique_ID>.vf.com'
 
# Put the PASSWORD value from your Email Delivery SMTP password into the following file.
PASSWORD_SMTP_FILE = 'ociemail.config'
 
# If you're using Email Delivery in a different region, replace the HOST value with an appropriate SMTP endpoint.
# Use port 25 or 587 to connect to the SMTP endpoint.
HOST = "smtp.us-ashburn-1.oraclecloud.com"
PORT = 587
 
# The subject line of the email.
SUBJECT = 'Email Delivery Test (Python smtplib)'
 
# The email body for recipients with non-HTML email clients.
BODY_TEXT = ("Email Delivery Test\r\n"
             "This email was sent through the Email Delivery SMTP "
             "Interface using the Python smtplib package."
            )
 
# The HTML body of the email.
BODY_HTML = """<html>
<head></head>
<body>
  <h1>Email Delivery SMTP Email Test</h1>
  <p>This email was sent with Email Delivery using the
    <a href='https://www.python.org/'>Python</a>
    <a href='https://docs.python.org/3/library/smtplib.html'>
    smtplib</a> library.</p>
</body>
</html>"""

# get the password from a named config file ociemail.config
with open(PASSWORD_SMTP_FILE) as f:
    password_smtp = f.readline().strip()

# create message container
msg = EmailMessage()
msg['Subject'] = SUBJECT
msg['From'] = email.utils.formataddr((SENDERNAME, SENDER))
msg['To'] = RECIPIENT

# make the message multi-part alternative, making the content the first part
msg.add_alternative(BODY_TEXT, subtype='text')
# this adds the additional part to the message
# According to RFC 2046, the last part of a multipart message, in this case
# the HTML message, is best and preferred.
msg.add_alternative(BODY_HTML, subtype='html')

# Try to send the message.
try: 
    server = smtplib.SMTP(HOST, PORT)
    server.ehlo()
    # most python runtimes default to a set of trusted public CAs that will include the CA used by OCI Email Delivery.
    # However, on platforms lacking that default (or with an outdated set of CAs), customers may need to provide a capath that includes our public CA.
    server.starttls(context=ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH, cafile=None, capath=None))
    # smtplib docs recommend calling ehlo() before & after starttls()
    server.ehlo()
    server.login(USERNAME_SMTP, password_smtp)
    # our requirement is that SENDER is the same as From address set previously
    server.sendmail(SENDER, RECIPIENT, msg.as_string())
    server.close()
# Display an error message if something goes wrong.
except Exception as e:
    print(f"Error: {e}")
else:
    print("Email successfully sent!")

已知的的问题

因为甲骨文发件人用户名是自动生成的,且长度非常的长,这导致在 Gmail 里配置该 SMTP 发送服务的时候,验证的时候失败,网上已经有其他人也发现了同样的问题:

这个目前暂时无解。

另外,在电子邮件域的页面,会一直显示一个”未验证“的状态提示,因为我们的域名不是放在甲骨文托管的,这个要把域名放在甲骨文的域管理里添加并验证,才可以通过。这个可以不用管,不影响我们配置和使用发信服务。

总结

在此之前,本博客的评论回复邮件通知功能,以及本站的联系邮箱的发信功能都是使用 Resend 这个服务( Resend 底层是基于 Amzon 的 SES)的免费套餐:每天100封免费,一直用着也不错,配置简单。

但这次因为上面那个 Gmail 的已知问题,没办法全部切换为甲骨文的方案。所以我目前仅仅把评论回复通知功能切换为了自己的 Oracle Email Delivery 服务。

你可以在这篇文章地下评论,当有人回复你的时候,通知邮件就是由我的 Oracle Email Delivery 递送的。

#Tech