2

I have a domain example.com set up as follows

  • A server hosts a website and other some other stuff
  • Google Apps handles my email and is configured to send and receive it

Whenever the server needs to send me an email, it uses Postfix to send the email through Google's SMTP servers.

This works perfectly fine, but the server sends emails as me@example.com. I set up an alias in Google Apps to allow me@example.com to also send and receive mail as server@example.com. I want postfix to send emails as server@example.com while logging into Google's SMTP server as me@example.com. The simple solution would be to open another apps account for my server, but that's another 5 bucks a month for a small hobby project.

0

But it works out from the box (with one little exception, see below). no-reply@sys-adm.org.ua it's an alias for the main email account alex.hha@sys-adm.org.ua

# echo "Hello world" | swaks -4 --server smtp.gmail.com:587 --from no-reply@sys-adm.org.ua \
--to alex.hha@gmail.com -tls --auth PLAIN --auth-user alex.hha@sys-adm.org.ua \
--auth-password 1234567 --h-Subject TEST --h-From: '"Do not reply" <no-reply@sys-adm.org.ua>' --body -
=== Trying smtp.gmail.com:587...
=== Connected to smtp.gmail.com.
<-  220 smtp.gmail.com ESMTP un6sm65521lbb.18 - gsmtp
 -> EHLO svn.example.net
<-  250-smtp.gmail.com at your service, [77.122.73.151]
<-  250-SIZE 35882577
<-  250-8BITMIME
<-  250-STARTTLS
<-  250-ENHANCEDSTATUSCODES
<-  250-PIPELINING
<-  250-CHUNKING
<-  250 SMTPUTF8
 -> STARTTLS
<-  220 2.0.0 Ready to start TLS
=== TLS started with cipher TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128
=== TLS no local certificate set
=== TLS peer DN="/C=US/ST=California/L=Mountain View/O=Google Inc/CN=smtp.gmail.com"
 ~> EHLO svn.example.net
<~  250-smtp.gmail.com at your service, [77.122.73.151]
<~  250-SIZE 35882577
<~  250-8BITMIME
<~  250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
<~  250-ENHANCEDSTATUSCODES
<~  250-PIPELINING
<~  250-CHUNKING
<~  250 SMTPUTF8
 ~> AUTH PLAIN VhAEBMZXHN7cyxhAGFG0ub9JnLnZaGhfsuaGhhQhhLTEiNTU8Ng==
<~  235 2.7.0 Accepted
 ~> MAIL FROM:<no-reply@sys-adm.org.ua>
<~  250 2.1.0 OK un6sm65521lbb.18 - gsmtp
 ~> RCPT TO:<alex.hha@gmail.com>
<~  250 2.1.5 OK un6sm65521lbb.18 - gsmtp
 ~> DATA
<~  354  Go ahead un6sm65521lbb.18 - gsmtp
 ~> Date: Wed, 09 Mar 2016 21:15:09 +0000
 ~> To: alex.hha@gmail.com
 ~> From: "Do not reply" <no-reply@sys-adm.org.ua>
 ~> Subject: TEST
 ~> X-Mailer: swaks v20130209.0 jetmore.org/john/code/swaks/
 ~>
 ~> Hello world
 ~>
 ~>
 ~> .
<~  250 2.0.0 OK 1457558110 un6sm65521lbb.18 - gsmtp
 ~> QUIT
<~  221 2.0.0 closing connection un6sm65521lbb.18 - gsmtp
=== Connection closed with remote host.

enter image description here

The exception.

In the headers you still can see the original sender user (Sender: Alex Domoradov )

Return-Path: <no-reply@sys-adm.org.ua>
Received: from svn.example.net ([77.122.73.151])
        by smtp.gmail.com with ESMTPSA id un6sm65521lbb.18.2016.03.09.13.15.10
        for <alex.hha@gmail.com>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Wed, 09 Mar 2016 13:15:10 -0800 (PST)
Message-ID: <56e0925e.2697700a.37e97.066f@mx.google.com>
Sender: Alex Domoradov <alex.hha@sys-adm.org.ua>
Date: Wed, 09 Mar 2016 21:15:09 +0000
To: alex.hha@gmail.com
From: "Do not reply" <no-reply@sys-adm.org.ua>
Subject: TEST
X-Mailer: swaks v20130209.0 jetmore.org/john/code/swaks/

Hello world

P.S. you must add the alias on the Account settings page

enter image description here

0

So, it turns out I needed to do two things to get it working.

First of all, It's not enough simply to alias the email addresses in the Google Apps admin panel, rather it's important to also add the additional address to the 'Send Mail As' panel in the settings page, per Alex's answer. If you don't, Gmail moves the old from address to an extra header and sends with one you're authorized to use.

Secondly, Postfix must be configured to use smtp_generic_maps. This automatically maps internal addresses to external ones according to a file specified in /etc/postfix/main.cf If you want your server to receive mail, you should also use canonical_maps.

The configuration I used was meant to force postfix to send all emails by all users as server@example.com

/etc/postfix/main.cf:

smtp_generic_maps = hash:/etc/postfix/generic

/etc/postfix/generic:

root@example.com                server@example.com
me@example.com                  server@example.com
@example.com                    server@example.com
@server-hostname                server@example.com
@server-hostname.example.com    server@example.com

Docs at http://www.postfix.org/ADDRESS_REWRITING_README.html#generic

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.