最近我們想將 GCP Compute Engine 與 Google suite 電子郵件服務連結。在這文件告訴那
Google Compute Engine 不允許連接埠 25 上的出站連線。此外,擁有值得信賴的第三方提供者(例如 SendGrid、Mailgun 或 Mailjet)可以減輕 Compute Engine 和您在接收者中維護 IP 聲譽的負擔。
我們的想法是我們有 php 腳本並在 httpd/apache 上運行,它具有mail
向我們的銷售團隊發送電子郵件的功能,如下所示
$mail = mail($siteOwnersEmail, $subject, $message, $headers);
並使用 sendmail 中繼到 smtp google 服務。我們的運算引擎在 Centos 7 上SendGrid
運作MailGun
。MailJet
來自另一個郵政,連接 Compute Engine 和 Google Suite 是很難做到的。我們需要您的幫助來實現這一目標。
我們已經配置sendmail如下
divert(-1)dnl
include(`/usr/share/sendmail-cf/m4/cf.m4')dnl
VERSIONID(`setup for linux')dnl
OSTYPE(`linux')dnl
dnl define(`confSMTP_LOGIN_MSG', `$j Sendmail; $b')dnl
dnl define(`confLOG_LEVEL', `9')dnl
dnl define(`SMART_HOST', `relay-smtp.gmail.com')dnl
define(`confDEF_USER_ID', ``8:12'')dnl
dnl define(`confAUTO_REBUILD')dnl
define(`confTO_CONNECT', `1m')dnl
define(`confTRY_NULL_MX_LIST', `True')dnl
define(`confDONT_PROBE_INTERFACES', `True')dnl
define(`PROCMAIL_MAILER_PATH', `/usr/bin/procmail')dnl
define(`ALIAS_FILE', `/etc/aliases')dnl
define(`STATUS_FILE', `/var/log/mail/statistics')dnl
define(`UUCP_MAILER_MAX', `2000000')dnl
define(`confUSERDB_SPEC', `/etc/mail/userdb.db')dnl
define(`confPRIVACY_FLAGS', `authwarnings,novrfy,noexpn,restrictqrun')dnl
define(`confAUTH_OPTIONS', `A')dnl
dnl define(`RELAY_MAILER_ARGS', `TCP $h 587′)dnl
dnl define(`ESMTP_MAILER_ARGS', `TCP $h 587′)dnl
dnl define(`confAUTH_OPTIONS', `A p')dnl
dnl TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
dnl define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
dnl define(`confCACERT_PATH', `/etc/pki/tls/certs')dnl
dnl define(`confCACERT', `/etc/pki/tls/certs/ca-bundle.crt')dnl
dnl define(`confSERVER_CERT', `/etc/pki/tls/certs/sendmail.pem')dnl
dnl define(`confSERVER_KEY', `/etc/pki/tls/certs/sendmail.pem')dnl
dnl define(`confDONT_BLAME_SENDMAIL', `groupreadablekeyfile')dnl
dnl define(`confTO_QUEUEWARN', `4h')dnl
dnl define(`confTO_QUEUERETURN', `5d')dnl
dnl define(`confQUEUE_LA', `12')dnl
dnl define(`confREFUSE_LA', `18')dnl
define(`confTO_IDENT', `0')dnl
dnl define(`confINET_QOS', `AF11')dnl
dnl FEATURE(delay_checks)dnl
FEATURE(`no_default_msa', `dnl')dnl
FEATURE(`smrsh', `/usr/sbin/smrsh')dnl
FEATURE(`mailertable', `hash -o /etc/mail/mailertable.db')dnl
FEATURE(`virtusertable', `hash -o /etc/mail/virtusertable.db')dnl
FEATURE(redirect)dnl
FEATURE(always_add_domain)dnl
FEATURE(use_cw_file)dnl
FEATURE(use_ct_file)dnl
dnl define(`confMAX_DAEMON_CHILDREN', `20')dnl
dnl define(`confCONNECTION_RATE_THROTTLE', `3')dnl
FEATURE(local_procmail, `', `procmail -t -Y -a $h -d $u')dnl
FEATURE(`access_db', `hash -T<TMPF> -o /etc/mail/access.db')dnl
FEATURE(`blacklist_recipients')dnl
EXPOSED_USER(`root')dnl
dnl define(`confLOCAL_MAILER', `cyrusv2')dnl
dnl define(`CYRUSV2_MAILER_ARGS', `FILE /var/lib/imap/socket/lmtp')dnl
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
dnl DAEMON_OPTIONS(`Port=submission, Name=MSA, M=Ea')dnl
dnl DAEMON_OPTIONS(`Port=smtps, Name=TLSMTA, M=s')dnl
dnl DAEMON_OPTIONS(`port=smtp,Addr=::1, Name=MTA-v6, Family=inet6')dnl
dnl DAEMON_OPTIONS(`Name=MTA-v4, Family=inet, Name=MTA-v6, Family=inet6')
FEATURE(`accept_unresolvable_domains')dnl
dnl FEATURE(`relay_based_on_MX')dnl
LOCAL_DOMAIN(`localhost.localdomain')dnl
dnl MASQUERADE_AS(`qreatiq.com')dnl
dnl FEATURE(masquerade_envelope)dnl
dnl FEATURE(masquerade_entire_domain)dnl
dnl MASQUERADE_DOMAIN(localhost)dnl
dnl MASQUERADE_DOMAIN(localhost.localdomain)dnl
dnl MASQUERADE_DOMAIN(mydomainalias.com)dnl
dnl MASQUERADE_DOMAIN(mydomain.lan)dnl
MAILER(smtp)dnl
MAILER(procmail)dnl
dnl MAILER(cyrusv2)dnl
並且已經設定 SELinux 如下
setsebool httpd_can_sendmail on
產生證書
cd /etc/pki/tls/certs
make sendmail.pem
建立用於身份驗證的身份驗證文件smtp.gmail.com
mkdir /etc/mail/auth
chmod 700 /etc/mail/auth
建立客戶資訊文件
AuthInfo:smtp.gmail.com “U:smmsp” “I:gmail_address” “P:password” “M:PLAIN”
AuthInfo:smtp.gmail.com:587 “U:smmsp” “I:gmail_address” “P:password” “M:PLAIN”
和做
makemap -r hash client-info.db < client-info
chmod 600 client-info client-info.db
編輯別名
root:email_address
apache
在受信任的用戶處新增使用者並運行newaliases
比我嘗試使用此代碼發送電子郵件
echo ‘this is a test’| mail -s test_email [email protected]
此處的cek 日誌/var/log/maillog
狀態deferred because connection timeout with aspmx2.googlemail.com
是完整的堆疊跟踪
Aug 30 06:54:03 gcp***-***a sendmail[14979]: w7U6s31m014979: to=system@*****.com, ctladdr=a*****g_imannuel (1001/1002), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30234, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (w7U6s3QN014980 Message accepted for delivery)
Aug 30 06:59:03 gcp***-***a sendmail[14982]: w7U6s3QN014980: to=<system@*****.com>, ctladdr=<a*****g_imannuel@gcp***-***a.c.calm-ca***-XXX.internal> (1001/1002), delay=00:05:00, xdelay=00:05:00, mailer=esmtp, pri=120537, relay=aspmx2.googlemail.com. [173.194.66.26], dsn=4.0.0, stat=Deferred: Connection timed out with aspmx2.googlemail.com.
並僅記錄 /var/log/messages 為 ssh 啟動的會話。
此外,這是我們 Google 套件中的 SMTP 中繼服務
Allowed senders: Any addresses (not recommended)
Only accept mail from the specified IP addresses: Yes
Allowed IP addresses: www.****.com
Require SMTP Authentication: Yes
Require TLS encryption: No
檢查 Google Suite - Gmail 應用程序,電子郵件永遠不會發送給寄件者。好難過。有人知道是什麼問題嗎?
答案1
在這裡使用 sendmail 會使事情變得過於複雜(並且可能仍然想使用連接埠 25)。只需按照此處的說明進行操作即可:https://support.google.com/a/answer/2956491?hl=en設定 GSuite 來中繼電子郵件、使用身分驗證並使用連接埠 587 傳送。
您也不能使用內建的 PHP mail() 函數(可能沒有人應該這樣做)。使用 PEAR::Mail 代替:http://pear.php.net/manual/en/package.mail.mail.php- 此軟體包可讓您設定主機/連接埠等。