关于在现有应用程序中配置Google Cloud服务中的电子邮件,我有些疑问
1.我们使用端口587的gmail帐户配置SMTP并尝试从我们的谷歌云实例发送邮件,没有发送电子邮件。我们尝试ping到端口587,它显示连接被拒绝。为什么会这样?
我们已经看到了在Google云平台上使用SMTP-Relay发送电子邮件的选项。如何使用SMTP-Relay设置使用Google Apps电子邮件/ gmail配置和设置SMTP?
我可以使用以下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。