Nginx - Email Forwarders

9,155

Solution 1

There's a similar question here: https://stackoverflow.com/questions/511198/nginx-as-mail-proxy with a geeky answer but the very easy answer would be: no.

The thing is: while nginx does have a mail module and mail proxy features capable of handling smpt, imap, pop3 I'm having an hard time understanding which configuration does really require this. I'm not even sure it is compiled by default with pop/smpt/imap support, so you might have to rebuild it yourself. My point is not that you can't do it, just that it's overkill because there are easier ways.

This is a sample nginx conf (from here) for dealing with mail:

# To proxy pop3/imap/smtp recommended to set to the number of CPU
  worker_processes 1;

  error_log / var / log / nginx / error.log info;

  mail {
      server_name ORIGINALMAILSERVERNAME;
      auth_http LOCALSERVERAUTH; #NGINX FORWARDS AUTHENTICATION REQUESTS TO THIS URL

      imap_capabilities "IMAP4rev1" "UIDPLUS" "IDLE" "LITERAL +" "QUOTA";

      pop3_auth plain apop cram-md5;
      pop3_capabilities "LAST" "TOP" "USER" "PIPELINING" "UIDL";

      smtp_auth login plain cram-md5;
      smtp_capabilities "SIZE 10485760" ENHANCEDSTATUSCODES 8BITMIME DSN;
      xclient off;

      server {
          listen 25;
          protocol smtp;
          # The RFC 2821 timeout should be 300 seconds
          timeout 300s;
      }
      server {
          listen 110;
          protocol pop3;
          proxy on;
          proxy_pass_error_message on;
      }
      server {
          listen 143;
          protocol imap;
          proxy on;
      }
      server {
          listen 587;
          protocol smtp;
          timeout 300s;
      }
  }

In each of the Server { listen } section you can do whatever you want, including proxying to other severs such as gmail.

But I suppose you have bought a domain name: most domain name registrar still propose some interfaces to simply redirect emails - that's definitely the easiest way. Set up a catch-all to go to your gmail address.

Otherwise: edit your domain DNS settings, get a google app account and follow their tutorial; it's free up to 10 accounts: http://www.google.com/apps/intl/en/group/index.html and very easy.

You will need to edit your DNS settings. Depending on where you registered your 'mysite.com' domain name mileage will vary.

Unluckily I can't provide you with specific links, but you should do the following:

from there, you will get very detailed instructions.

There are probably other hosted mail solutions, and I do not work at google, but you want to read mails in a gmail interface so this should be the easiest way. I have myself a free google app account myself and very happy with it;

Solution 2

As stated by Stefano, no.

If you want to forward [email protected] to [email protected], then go to your site.com email provider and setup forwarding for the account.

Share:
9,155

Related videos on Youtube

TheBlackBenzKid
Author by

TheBlackBenzKid

Ecommerce specialist with 15+ years of experience in development, design, marketing and management. Application Acceleration CDN, Load balancing and performance NodeJS, Vanilla JS, AngularJS IBM WebSphere Commerce Fast Fashion advocate - love ecommerce, love luxury fashion Oracle ATG Web Commerce OPENCART Stack: NodeJS, PHP, NGINX, Smarty or a JS view framework Omni channel and mutli channel advocate PHP/MySQL/HTML5/CSS3/JavaScript/Nginx/Rackspace/AWS/jQuery/SaSS also GULP over WebPack (some fanboy love for ya!) oh.. and DEFO FLASH and GIF! As Gif and Flash will always come back with a boom! 2018 Big fan of Blockchain, Cryptography, Hash graph and block chain development

Updated on September 18, 2022

Comments

  • TheBlackBenzKid
    TheBlackBenzKid almost 2 years

    I used to have a CPanel/Plesk server so I didn't setup email via command line etc.

    I don't want an email pop3 account or mail server. Just want to forward "[email protected]" to "[email protected]" - can I do this using nginx?

    K

    • Dayo
      Dayo over 12 years
      I believe we might have a case of the XY Problem here (perlmonks.org/index.pl?node_id=5423410 and that the real question is "How do I set up my server to use gmail to process my email". If this is indeed the case, then this is a server configuration question that would probably be better asked on serverfault. BTW, I personally use this and it is not related to nginx or anyother webserver.
    • Dayo
      Dayo over 12 years
      Very enlightening. Good luck with your quest.
    • Stefano
      Stefano over 12 years
      what's your domain name registrar?
  • Martin Samson
    Martin Samson over 12 years
    uh i think you are misunderstanding what an email server is vs web server. If you want to forward your mail, just use the settings your domain provider gives you to setup forwarding.
  • DaveTheMinion
    DaveTheMinion over 12 years
    what about nginx actually acting as a mail server? I have seen settings in conf files for smtp and other commands..
  • Stefano
    Stefano over 12 years
    @TheBlackBenzKid: why do you want to do something difficult when you can do something easy? I'm updating my answer with a few more details..
  • Stefano
    Stefano over 12 years
    @TheBlackBenzKid also, you should have provided more details including who's your registrar and what's your current DNS configuration to get more detailed help!
  • DaveTheMinion
    DaveTheMinion over 12 years
    I marked both @MartinSamson and yourself (@Stefano) repped. This is the closest thing I will come to it. I already have Gmail forwards via the Google app on this domain. DNS is DynDNS who handle mail ironically and Host is Rackspace (they given basic DNS options in the admin for MX records so does DynDns). I am happy with this answer. I will have to keep looking around nginx to see what can be done. Alternative is since the server instance is on Ubuntu 11 - might as well get a Cpanel.. an opensource one that supports nginx..
  • DaveTheMinion
    DaveTheMinion over 12 years
    an opensource cpanel that supports nginx I am guessing will build in the mail handlers.
  • Stefano
    Stefano over 12 years
    @TheBlackBenzKid: stackoverflow.com/questions/670628/… for open source "cpanels".. But really, doing DNS based mail configuration is the best way to use gmail: I can't imagine what nginx could provide more. I guess that your domain name registrar is Rackspace, so you should not even need DynDNS that provide paid-for mail redirection.
  • Stefano
    Stefano over 12 years
  • RaisinBranCrunch
    RaisinBranCrunch over 7 years
    But I am site.com... which is why I came here to learn how to redirect mails to an external server, because I don't want to bog down my server with webmail cogs when I can just redirect them.