Oracle云不允许local SMTP外发邮件,需要通过指定的Cloud Infrastructure SMTP邮件服务器转发


第一步:参考以下链接配置Oracle Cloud Infrastructure 中提供的 SMTP 邮件服务器


https://docs.oracle.com/cloud/help/zh_CN/analytics-cloud/ACABI/GUID-0E6640DD-4940-4DC9-B0AE-4E5F0CA4CA17.htm#ACABI-GUID-0E6640DD-4940-4DC9-B0AE-4E5F0CA4CA17

https://blogs.oracle.com/cloud-infrastructure/post/step-by-step-instructions-to-send-email-with-oci-email-delivery



关键点小节:


在OCI身份域生成SMTP身份证明,并复制保存ID和pw;注意复制下来,因为关闭了不能再次显示,所以忘记了后只能重新生成;

OCI的STMP配置:

 

第二步,在你的cloud虚拟机ubuntu里安装mailutils


Sudo apt install mailutils 居然提示无安装candidate…. 无奈


1.   Sudo apt-get update -y


2.   Sudo apt-get upgrade


3.   Sudo apt-get install -y mailutils


4.   安装mailutils时也会安装postfix, 注意postfix会提示安装选项Internet with smarthost


5.   如果4选错了,可以后面卸载postfix重新安装之如下三步


a)    Sudo apt-get remove --purge postfix


b)   Sudo apt-get autoremove –purge postfix


c)    Sudo apt-get install -y postfix


 

第三步:修改ubnutu下的postfix 设置,让第二部安装的postfix作为客户端登录到第一步获得的SMTP服务器发邮件


编辑/etc/postfix/main.cf:添加


relayhost = smtp.email.us-phoenix-1.oci.oraclecloud.com:587

smtp_sasl_auth_enable = yes

smtp_sasl_security_options = noanonymous

smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd

smtp_sender_dependent_authentication = yes

smtp_generic_maps = hash:/etc/postfix/generic


新建 /etc/postfix/sasl_passwd ,里边写第一步身份域获得的SMTP身份证明ID和密码

smtp.email.us-phoenix-1.oci.oraclecloud.com:587 ID:pw


新建/etc/postfix/generic 里配置发件人替代:

ubuntu@ubuntu0520.com xyz@aliyun.com

这句配置的意思是,发件人匹配前面的情况就把它改写成 后面这个 (第一步里的批准的发件人)。


然后生存 hash 数据库,并更改权限:

postmap /etc/postfix/sasl_passwd

postmap /etc/postfix/generic

chmod 600 /etc/postfix/sasl_passwd*


就绪,启动或者重新加载 Postfix 就可以了:Sudo postfix reload


第四步:就绪,测试

发邮件: Echo ‘hello mail’ | Mail -s ‘test’ xxx@yyy.com

看log: vim /var/log/mail.log

检查端口开放: sudo nmap localhost