Welcome to Centmin Mod Community
Register Now

Amazon AWS Email Setting up email forwarding

Discussion in 'Domains, DNS, Email & SSL Certificates' started by Lav, Apr 16, 2020.

  1. Lav

    Lav Member

    49
    1
    8
    Feb 23, 2020
    Ratings:
    +1
    Local Time:
    4:15 PM
    1.17.8
    10.3
    Please fill in any relevant information that applies to you:
    • CentOS Version: CentOS 7 64bit
    • Centmin Mod Version Installed: 123.09beta01
    • Nginx Version Installed: 1.17.10
    • PHP Version Installed: 7.3.16
    • MariaDB MySQL Version Installed: 10.3
    I have successfully set up postfix email server with Amazon SES and it is working great as I have created a test email and it is getting delivered.
    Now I want to know what else do I need to do to make email forwarding from
    Code:
    /var/spool/mail/root
    to my own email address. I have set up my email address in the
    Code:
    /root/.forward
    file as
    Code:
    myemail@gmail.com
    . Is that sufficient or do I need to make any additional changes?


    I want to make some test emails so that emails from
    Code:
    /var/spool/mail/root
    gets forwarded to my email address present in
    Code:
    /root/.forward
    file?

    Also if I am using Amazon SES as email forwarding system then do I need to set hostname as host.domain.com as A name to the server ip address along with spf records in DNS. Will it serve any purpose then?
     
  2. Lav

    Lav Member

    49
    1
    8
    Feb 23, 2020
    Ratings:
    +1
    Local Time:
    4:15 PM
    1.17.8
    10.3
    I have entered 'TO' email address in
    Code:
    /root/.forward
    but do I need to enter the 'FROM' email address too somewhere so that system can understand the email address via which it has to send email address which is also verified in the Amazon SES ?
     
  3. eva2000

    eva2000 Administrator Staff Member

    58,895
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    8:45 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    Getting Started Guide step 18 for managing root emails at Getting Started Guide - CentminMod.com LEMP Nginx web stack for CentOS
    If you have setup working AWS SES smtp server as a Postfix relay, then you do not need SPF/DKIM etc on main hostname as outlined at Email - Steps to ensure your site/server email doesn't end up in spam inboxes. But I'd do it anyway to be on the safe side if you ever want to reverse the Postfix relay setup.

    All you need is email address you want emails to go to in .forward file. Test and see by inspecting received email's source headers.
     
  4. Lav

    Lav Member

    49
    1
    8
    Feb 23, 2020
    Ratings:
    +1
    Local Time:
    4:15 PM
    1.17.8
    10.3
    How should I test? Any way to send a test mail to the root folder so that it gets forward to regular email account via .forward file?
     
  5. eva2000

    eva2000 Administrator Staff Member

    58,895
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    8:45 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
  6. Lav

    Lav Member

    49
    1
    8
    Feb 23, 2020
    Ratings:
    +1
    Local Time:
    4:15 PM
    1.17.8
    10.3
    Just checked mail logs and it says
    Code:
    554 Message rejected: Email address is not verified.
    . I want to change the default sending email address
    Code:
    root@host.localdomain
    to
    Code:
    myemail@gmail.com
    cause
    Code:
    root@host.localdomain
    is not verified in my Amazon SES therefore SES rejects the emails from that address.
    Is there some any other default from email address also cause I have seen one more email address such as nginx-host.localhost or something like that. I want to change all of this to a verified email address in SES. How to get the list of all email address which are going to send emails to root file.
    I followed some guides but didn't worked cause the email forwarding is not happening such as https://superuser.com/a/695191.
    I am able to send email address by using this
    Code:
     
    echo "mail-test" | mail -s "mail-tester" -r user@domain.com your@gmail.com 
    by changing user@domain.com to one of my verified emails on SES but can't send emails by using
    Code:
    echo "mail-test" | mail -s "mail-tester" your@gmail.com
    .
     
  7. eva2000

    eva2000 Administrator Staff Member

    58,895
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    8:45 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    You should be able to send with just .forward and single email address. You need to ensure Amazon SES has validated both your domain itself + the sending from email addresses. You maybe missing validation of your domain itself.

    I tested on my Centmin Mod server with Postfix relay setup for Amazon SES smtp using mail-test command line with either to address as my @mydomain.com or @gmail.com and both received emails fine.

    Gmail headers mailed-by ses.mydomain.com and signed by mydomain.com (masked for privacy) and from address the default root@myhostname.mydomain.com

    postfix-relay-working-headers-01.png
     
  8. Lav

    Lav Member

    49
    1
    8
    Feb 23, 2020
    Ratings:
    +1
    Local Time:
    4:15 PM
    1.17.8
    10.3
    My domain is verified but the email address of root user is not verified on my amazon SES account and that is why I was getting the error. I was trying to change the FROM email address of root user to one of the verified email address of SES but wasn't able to do so. But I got it figured out this way.

    Code:
    /etc/postfix/main.cf:
    
    sender_canonical_classes = envelope_sender, header_sender
    sender_canonical_maps =  regexp:/etc/postfix/sender_canonical_maps
    smtp_header_checks = regexp:/etc/postfix/header_check
    Code:
    /etc/postfix/sender_canonical_maps:
    
    /.+/    newsender@address.com
    Code:
    /etc/postfix/header_check:
    
    /From:.*/ REPLACE From: newsender@address.com
    newsender@address.com is replaced by one of the verified emails of SES an now it is working great and it is forwarding emails to my designated email.

    Just wanted to know if this method is fine and will not cause any conflicts with other elements of the server.
    Thanks!!
     
  9. eva2000

    eva2000 Administrator Staff Member

    58,895
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    8:45 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    If it works for you should be fine, though I didn't have to do any such thing for me to get it to work as you can see in screenshot I posted where from address is just root@host.domain.com. If i check my receiving @gmail.com email's source headers I see the SPF entry that allowed it as
    Code (Text):
    Received-SPF: pass (google.com: domain of XXXXX0@ses.mydomain.com designates 54.240.xxx.xxx as permitted sender) client-ip=54.240.xxx.xxx;

    I believe this is because I also setup a custom MAIL FROM domain in AWS SES for ses.mydomain.com which allowed me to pass SPF

    Steps for DMARC compliance via SPF: Setting Up Custom MAIL FROM Domain
    that is what you see in my above Gmail screenshot partially masked for SSH command line sent email from root@host.domain.com to @gmail.com

    mailed-by = ses.mydomain.com is AWS set MAIL FROM domain
    signed-by = host.mydomain.com is my server's main hostname
     
    Last edited: Apr 17, 2020
  10. Lav

    Lav Member

    49
    1
    8
    Feb 23, 2020
    Ratings:
    +1
    Local Time:
    4:15 PM
    1.17.8
    10.3
    I don't know but that may be the reason. For me I have already setup custom MAIL FROM DOMAIN on Amazono SES which mail.mydomain.com. I cannot add another custom mail from domain and don't want to change mail.mydomain.com. So I guess for me the above method is good and I am happy with it.

    Thanks for your help throughout the entire learning process. It took me some time cause I am not a programmer but I have learned a lot. You have made a wonderful product and especially your support is something which makes it a different and best combination among all the stacks out there. Thanks!!