Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
OGoogle Cloud trabalha com o Mailgun para fornecer um serviço de e-mail que tenha
uma API programática, retenção de registros, personalização, análise e validação
de e-mails.
As instruções a seguir mostram como configurar o Mailgun como um redirecionamento
de e-mail com o Postfix.
Solicite suas credenciais. Nas instruções, você precisará fornecer seu nome de usuário, senha e nome de host SMTP do Mailgun. Solicite seu nome de usuário e senha no painel de controle do Mailgun, na seção Domínios.
Dependendo de como o domínio está configurado no Mailgun, o nome do host SMTP é
smtp.mailgun.org ou smtp.eu.mailgun.org.
Configure as regras de firewall para permitir tráfego de saída na porta TCP 2525.
Como configurar o Mailgun como um redirecionamento de e-mail com o Postfix
Configurar o Mailgun como um redirecionamento de e-mail permite que o agente de transferência de e-mail do Postfix (em inglês) encaminhe e-mails destinados à entrega remota.
Conecte-se à instância usando SSH.
gcloudcomputessh[INSTANCE_NAME]
em que [INSTANCE_NAME] é o nome da instância de VM da qual os e-mails serão enviados.
Conecte-se como superusuário e configure um umask seguro.
Adicione o serviço SMTP do Mailgun incluindo a seguinte linha no fim do arquivo:
relayhost = [smtp.mailgun.org]:2525
Para aplicar o suporte SSL/TLS e configurar a autenticação SMTP para essas
solicitações, adicione as seguintes linhas ao final do arquivo: Na configuração do Postfix,
a autenticação é processada por um módulo de camada de acesso simples e
de segurança (SASL).
No prompt, insira os detalhes do serviço, substituindo YOUR_SMTP_LOGIN e YOUR_SMTP_PASSWORD pelas suas credenciais. Consulte a Ajuda
do Mailgun
para instruções sobre como ver ou alterar as credenciais por domínio.
root@test-instance:~# ls -la /etc/postfix/sasl_passwd.db
-rw------- 1 root root 12288 Aug 31 18:51 /etc/postfix/sasl_passwd.db
Por fim, atualize sua configuração para carregar os parâmetros modificados.
Debian
root@test-wheezy:~# /etc/init.d/postfix restart
CentOS
[root@test-centos ~]# postfix reload
Teste sua configuração. Instale o pacote mailx ou mailutils e teste a configuração.
Debian
root@test-wheezy:~# apt -y install mailutils
CentOS
[root@test-centos ~]# yum install mailx -y
Envie uma mensagem de teste.
root@test-instance:~# echo 'Test passed.' | mail -s 'Test-Email' EMAIL@EXAMPLE.COM
Nos registros do sistema, procure uma linha de status que contenha status e o código de resposta bem-sucedida do servidor (250).
Debian
root@test-wheezy:~# tail -n 5 /var/log/syslog
CentOS
[root@test-centos ~]# tail -n 5 /var/log/maillog
Para informações e exemplos detalhados sobre outros tópicos, como rastreamento e encaminhamento de mensagens, leia a documentação do Mailgun (em inglês).
Confira arquiteturas de referência, diagramas e práticas recomendadas do Google Cloud.
Confira o
Centro de arquitetura do Cloud.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 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)."]]