在Google Cloud Service中发送电子邮件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Google Cloud Service中发送电子邮件相关的知识,希望对你有一定的参考价值。

关于在现有应用程序中配置Google Cloud服务中的电子邮件,我有些疑问

1.我们使用端口587的gmail帐户配置SMTP并尝试从我们的谷歌云实例发送邮件,没有发送电子邮件。我们尝试ping到端口587,它显示连接被拒绝。为什么会这样?

我们已经看到了在Google云平台上使用SMTP-Relay发送电子邮件的选项。如何使用SMTP-Relay设置使用Google Apps电子邮件/ gmail配置和设置SMTP?

  1. 是否有任何选项可以在不使用SendGrid,Mailgun和Mailjet等第三方合作伙伴的情况下,为我们现有的应用程序(如mantis)发送来自Google云端的电子邮件?
答案

我可以使用以下mailx命令从我们的Google Compute实例发送电子邮件:

# the body of the alert email is saved to a temprary file
echo "Hello. This is a test message" > /tmp/mail_body.txt
# the mailx command is used to send the email. it sends the email using gmail server.
# this is useful on servers that have limited access to email servers such as Google Compute instance
mailx -s "Email Subject" -r "reply_email" -S smtp="smtp.gmail.com:587" -S    
smtp-use-starttls -S smtp-auth=login -S smtp-auth-user="gmail_address" -S smtp-auth-password="gmail_password" -S 
ssl-verify=ignore recepiant_email < /tmp/mail_body.txt
# the temprary file is removed
rm -rf /tmp/mail_body
另一答案

您不能使用端口587,因为GCP阻止来自该端口的所有出站流量,我建议您使用端口2525,因为这是GCP不阻止的唯一smtp端口。

另一答案

Google Cloud Engine会阻止587上的出站流量,请尝试使用端口2587。

以上是关于在Google Cloud Service中发送电子邮件的主要内容,如果未能解决你的问题,请参考以下文章

如何让我的 Google-service.json 与 Google Cloud Platform 中的 Firestore 一起使用?

Google Cloud Storage Transfer Service 失败并出现 UNKNOWN 错误

使用 Google Cloud Key Management Service 签署 JSON Web Tokens

Google Cloud Run 身份验证服务到服务

为啥我会通过 Google Cloud To Device Messaging Service 为我的设备获取多个活动令牌?

SERVICE_NOT_AVAILABLE 同时使用 Xamarin for Android 注册 Google Cloud Messaging