Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Google Cloud trabaja con Mailgun para proporcionar un servicio de correo electrónico que tiene una API programática, retención de registros, personalización del correo electrónico, estadísticas y validación de correo electrónico.
En las siguientes instrucciones, se muestra cómo configurar Mailgun como una retransmisión de correo electrónico con Postfix.
Obtén tu credencial Las instrucciones requieren que conozcas tu nombre de usuario, la contraseña y el nombre de host del SMTP de Mailgun. Obtén tu nombre de usuario y contraseña desde el panel de control de Mailgun, en la sección Dominios.
Según la configuración del dominio en Mailgun, el nombre de host del SMTP es smtp.mailgun.org o smtp.eu.mailgun.org.
Configura las reglas de firewall para permitir el tráfico saliente en el puerto TCP 2525.
Configura Mailgun como retransmisión de correo con Postfix
Si configuras Mailgun como servicio de retransmisión de correo, permitirás que el agente de transferencia de correo de Postfix reenvíe correos electrónicos destinados a la entrega remota.
Conéctate a la instancia mediante SSH.
gcloudcomputessh[INSTANCE_NAME]
[INSTANCE_NAME] es el nombre de la instancia de VM desde la que quieres enviar correo electrónico.
Conviértete en superusuario y establece una umask de seguridad.
user@test-instance:~$ sudo su -
root@test-instance:~# umask 077
Instala el agente de transporte de correos Postfix.
Cuando se te solicite, selecciona la configuración Local Only y acepta las opciones predeterminadas para los nombres de dominio.
Modifica las opciones de configuración de Postfix. Las opciones de configuración de Postfix se establecen en el archivo main.cf. Abre el archivo con el editor de texto que prefieras.
Para agregar el servicio SMTP de Mailgun, agrega la línea siguiente al final del archivo.
relayhost = [smtp.mailgun.org]:2525
Si quieres aplicar la compatibilidad con SSL/TLS y configurar la autenticación SMTP para estas solicitudes, agrega las siguientes líneas al final del archivo. Un módulo simple de acceso y capa de seguridad (SASL) maneja la autenticación en la configuración de Postfix.
Cuando se te solicite, ingresa los detalles del servicio y reemplaza YOUR_SMTP_LOGIN y YOUR_SMTP_PASSWORD por tus credenciales. Consulta la ayuda de Mailgun a fin de obtener instrucciones para ver o cambiar tus credenciales por dominio.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-08-19 (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)."]]