Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Google Cloud collabora con Mailgun per fornire un servizio email con API programmatica,
conservazione dei log, personalizzazione e convalida delle email e
dati e analisi.
Le istruzioni riportate di seguito mostrano come configurare Mailgun come relay di posta
con Postfix.
Ottieni le credenziali. Le istruzioni richiedono di conoscere il nome utente,
la password e il nome host SMTP di Mailgun. Recupera il nome utente e la password dal
pannello di controllo di Mailgun, nella sezione Domini.
In base alla configurazione del dominio in Mailgun, il nome host SMTP è
smtp.mailgun.org o smtp.eu.mailgun.org.
Configura le regole firewall
per consentire il traffico in uscita sulla porta TCP 2525.
Configurazione di Mailgun come relay di posta con Postfix
La configurazione di Mailgun come relay di posta consente
all'agente di trasferimento della posta Postfix di
inoltrare le email destinate alla consegna remota.
Connettiti all'istanza tramite SSH,
gcloudcomputessh[INSTANCE_NAME]
dove [INSTANCE_NAME] è il nome dell'istanza
da cui vuoi inviare email.
Diventa un super user e imposta un'umask protetta.
user@test-instance:~$ sudo su -
root@test-instance:~# umask 077
Installa l'agente di trasporto della posta Postfix.
Quando richiesto, seleziona la configurazione Local Only e accetta le scelte
predefinite per i nomi di dominio.
Modifica le opzioni di configurazione di Postfix. Le opzioni di configurazione di Postfix sono
impostate nel file main.cf. Apri il file con l'editor di testo che preferisci.
Aggiungi il servizio SMTP di Mailgun inserendo la seguente riga alla fine del
file.
relayhost = [smtp.mailgun.org]:2525
Per applicare il supporto SSL/TLS e configurare l'autenticazione SMTP per queste
richieste, aggiungi le seguenti righe alla fine del file. Un modulo SASL
(Simple Authentication and Security Layer) gestisce l'autenticazione nella configurazione
di Postfix.
Quando richiesto, inserisci i dettagli del servizio sostituendo YOUR_SMTP_LOGIN e
YOUR_SMTP_PASSWORD con le tue credenziali. Consulta la guida
di Mailgun
per istruzioni su come visualizzare o modificare le credenziali per dominio.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-09 UTC."],[[["\u003cp\u003eGoogle Cloud utilizes Mailgun for email services, offering a programmatic API, log retention, email personalization, analytics, and email validation.\u003c/p\u003e\n"],["\u003cp\u003eThis guide provides instructions on how to configure Mailgun as an email relay using Postfix, enabling the forwarding of emails for remote delivery.\u003c/p\u003e\n"],["\u003cp\u003eThe process involves setting up a Mailgun account, obtaining SMTP credentials, and configuring firewall rules to allow outgoing traffic on TCP port 2525.\u003c/p\u003e\n"],["\u003cp\u003ePostfix's \u003ccode\u003emain.cf\u003c/code\u003e file requires modifications to relay email through Mailgun, including setting the \u003ccode\u003erelayhost\u003c/code\u003e to \u003ccode\u003e[smtp.mailgun.org]:2525\u003c/code\u003e and configuring SMTP authentication with SSL/TLS support.\u003c/p\u003e\n"],["\u003cp\u003eUsers can test their configuration by sending a test email and verifying its successful delivery in the system logs, looking for a successful server response code (250).\u003c/p\u003e\n"]]],[],null,["*** ** * ** ***\n\nGoogle Cloud works with Mailgun to provide an email service that has a\nprogrammatic API, log retention, email personalization, analytics, and email\nvalidation.\n\nThe following instructions show you how to configure Mailgun as an email relay\nwith Postfix.\n\nBefore you begin\n\n1. Sign up for and create a new Mailgun account on the\n [Google Cloud Marketplace](https://console.cloud.google.com/marketplace/details/mailgun/emailapi).\n\n2. Get your credentials. The instructions require that you know your Mailgun\n SMTP username, password, and hostname. Get your username and password from\n the Mailgun control panel, under the **Domains** section.\n\n Depending on how the domain is configured in Mailgun, the SMTP hostname is\n either `smtp.mailgun.org` or `smtp.eu.mailgun.org`.\n3. Configure your [firewall rules](/vpc/docs/using-firewalls#creating_firewall_rules)\n to allow outgoing traffic on TCP port `2525`.\n\nConfiguring Mailgun as a mail relay with Postfix\n\nConfiguring Mailgun as a mail relay allows the\n[Postfix](http://www.postfix.org) mail transfer agent to\nforward emails destined for remote delivery.\n\n1. Connect to your instance using SSH.\n\n gcloud compute ssh [INSTANCE_NAME]\n\n where `[INSTANCE_NAME]` is the name of the VM instance where you want to\n send email from.\n2. Become a superuser and set a safe umask.\n\n ```\n user@test-instance:~$ sudo su -\n ``` \n\n ```\n root@test-instance:~# umask 077\n ```\n3. Install the Postfix Mail Transport Agent.\n\n\n Debian\n\n\n ```\n root@test-instance:~# apt update && apt -y install postfix libsasl2-modules\n ```\n\n \u003cbr /\u003e\n\n CentOS\n\n\n ```\n root@test-instance:~# yum install postfix cyrus-sasl-plain cyrus-sasl-md5 -y\n ```\n\n \u003cbr /\u003e\n\n \u003cbr /\u003e\n\n4. When prompted, select the `Local Only` configuration and accept the default\n choices for domain names.\n\n5. Modify the Postfix configuration options. Postfix configuration options are\n set in the `main.cf` file. Open the file with the text editor of your choice.\n\n ```\n root@test-instance:~# vi /etc/postfix/main.cf\n ```\n6. If they exist, comment out the following lines.\n\n # default_transport = error\n # relay_transport = error\n\n7. Add the Mailgun SMTP service by adding the following line to the end of the\n file.\n\n relayhost = [smtp.mailgun.org]:2525\n\n | **Note:** You must use port `2525` because port `25` isn't allowed on Compute Engine.\n8. To enforce SSL/TLS support and configure SMTP authentication for these\n requests, add the following lines to the end of the file. A simple access and\n security layer (SASL) module handles authentication in the Postfix\n configuration.\n\n smtp_tls_security_level = encrypt\n smtp_sasl_auth_enable = yes\n smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd\n smtp_sasl_security_options = noanonymous\n\n9. Save your changes and close the file.\n\n10. Generate the SASL password map.\n\n 1. Create a new password file that is ready for standard input.\n\n ```\n root@test-instance:~# cat \u003e /etc/postfix/sasl_passwd \u003c\u003c EOF\n ```\n 2. At the prompt, enter the service details, replacing `YOUR_SMTP_LOGIN` and\n `YOUR_SMTP_PASSWORD` with your credentials. See the [Mailgun\n help](https://help.mailgun.com/hc/en-us/articles/203380100-Where-Can-I-Find-My-API-Key-and-SMTP-Credentials)\n for instructions on how to view or change your per-domain credentials.\n\n ```\n \u003e [smtp.mailgun.org]:2525 YOUR_SMTP_LOGIN:YOUR_SMTP_PASSWORD\n ```\n 3. Close and save the file by typing the delimiter, `EOF`.\n\n ```\n \u003e EOF\n ```\n11. Use the `postmap` utility to generate a `.db` file.\n\n ```\n root@test-instance:~# postmap /etc/postfix/sasl_passwd\n ``` \n\n ```\n root@test-instance:~# ls -l /etc/postfix/sasl_passwd*\n\n -rw------- 1 root root 68 Jun 1 10:50 /etc/postfix/sasl_passwd\n -rw------- 1 root root 12288 Jun 1 10:51 /etc/postfix/sasl_passwd.db\n ```\n12. Next, remove the file that contains your credentials because it is no longer\n needed.\n\n ```\n root@test-instance:~# rm /etc/postfix/sasl_passwd\n ```\n13. Set the permissions on your `.db` file.\n\n ```\n root@test-instance:~# chmod 600 /etc/postfix/sasl_passwd.db\n ``` \n\n ```\n root@test-instance:~# ls -la /etc/postfix/sasl_passwd.db\n\n -rw------- 1 root root 12288 Aug 31 18:51 /etc/postfix/sasl_passwd.db\n ```\n14. Finally, reload your configuration to load the modified parameters.\n\n\n Debian\n\n\n ```\n root@test-wheezy:~# /etc/init.d/postfix restart\n ```\n\n \u003cbr /\u003e\n\n CentOS\n\n\n ```\n [root@test-centos ~]# postfix reload\n ```\n\n \u003cbr /\u003e\n\n \u003cbr /\u003e\n\n15. Test your configuration. Install the `mailx` or `mailutils` package and test\n your configuration.\n\n\n Debian\n\n\n ```\n root@test-wheezy:~# apt -y install mailutils\n ```\n\n \u003cbr /\u003e\n\n CentOS\n\n\n ```\n [root@test-centos ~]# yum install mailx -y\n ```\n\n \u003cbr /\u003e\n\n \u003cbr /\u003e\n\n Send a test message. \n\n ```\n root@test-instance:~# echo 'Test passed.' | mail -s 'Test-Email' EMAIL@EXAMPLE.COM\n ```\n\n Look in your systems logs for a status line containing `status` and the\n successful server response code `(250)`.\n\n\n Debian\n\n\n ```\n root@test-wheezy:~# tail -n 5 /var/log/syslog\n ```\n\n \u003cbr /\u003e\n\n CentOS\n\n\n ```\n [root@test-centos ~]# tail -n 5 /var/log/maillog\n ```\n\n \u003cbr /\u003e\n\n \u003cbr /\u003e\n\nFor detailed examples and information about other topics including\ntracking and routing messages, read the\n[Mailgun documentation](https://documentation.mailgun.com).\n\n\nExplore reference architectures, diagrams, and best practices about Google Cloud.\nTake a look at our\n[Cloud Architecture Center](/architecture)."]]