Creating a Mail Server on Ubuntu (Postfix, Courier, SSL/TLS, SpamAssassin, ClamAV, Amavis)

This guide is now compatible with Ubuntu 13.04
For earlier versions: Creating a Mail Server on Ubuntu (Postfix, Courier, SSL/TLS, SpamAssassin, ClamAV, Amavis)

Once again, credit where credit due: Thanks again to Ivar Abrahamsen for his guide which is, by far, one of the best ones out there.

Getting Started

This guide is intended to be a reference for setting up a server quickly. For that reason, I have intentionally omitted information which explains each step. Please feel free to ask any questions in the comments and I’ll try to answer you as quickly as possible.

There are several configuration variables that you will need to replace in certain configuration files. These occurrences are clearly marked during the guide. However, for your reference, here are the variables used:

  • mail.example.com
    The hostname for your mail server. This can be anything you like, however, it should match the public hostname as specified by your DNS records if you want to expose the server over the Internet.
  • rootpassword
    The password for the MySQL root user. You should pick something unique and secure; but something you can remember.
  • mailpassword
    The password for the MySQL mail user. You should pick something unique and secure; you don’t even have to remember it beyond this tutorial.
  • adminpassword
    The password for the administrator e-mail account that you’ll create later in the guide.

Installation

Enter rootpassword.

Enter rootpassword.

Choose Ok.

Choose No.

Choose Ok.

Choose Internet Site.

Choose Ok.

Enter mail.example.com.

Choose Ok.

Virtual User

Note: All e-mail messages will be received by a single ‘virtual’ user. That is, only one system account needs to be created and we’ll manage mailboxes using the virtual user features of Postfix.

Note that we are forcing the user ID to 5000 as this value is referenced by configuration files later. If you need to use a different UID make sure you update the affected configuration files, too.

Postfix

Copy/paste:
Replace mail.example.com

Copy/paste:

Virtual Maps

Copy/paste:
Replace mailpassword

Copy/paste:
Replace mailpassword

Copy/paste:
Replace mailpassword

SASL Authentication (SSL/TLS)

Copy/paste:
Replace mailpassword

Copy/paste:

Copy/paste:
Replace mailpassword

Courier

Copy/paste:

Copy/paste:
Replace mailpassword

Copy/paste:

Copy/paste:
Replace mail.example.com

Copy/paste:

Copy/paste:
Replace mail.example.com

Note: In the next step you will be prompted to input some information about the certificate you create. You can enter any information you want here except Common Name (CN) which must match mail.example.com.

Amavis

Copy/paste:

SpamAssassin

Copy/paste:

ClamAV

Choose Ok.

Choose daemon.

Choose Ok.

Choose a mirror closest to your server.

Specify a proxy, if required.

Enter 24.

Choose No.

MySQL Database

Enter rootpassword.

Copy/paste:
Replace mailpassword

Create default data. This will:

  • Permit messages sent to the localhost domain
  • Permit messages sent to the localhost.localdomain domain
  • Permit messages sent to the example.com domain
  • Create a mailbox for admin@example.com with the password adminpassword
  • Forward messages to the localhost.localdomain domain to the localhost domain
  • Forward messages to the localhost domain to admin@example.com

Copy/paste:
Replace example.com and adminpassword

Finishing Up

Reboot Services

Create Your Mail Directory

You will not be able to login to your mailbox(es) until you create the required folder structure. There are two ways to do this:

  1. Send an e-mail to your new e-mail address from an existing e-mail account. Postfix will create the required directories for you.
  2. Create the directories yourself:

327 Comments

  1. Hi!

    This is works for me. I have one question… How do I add more users?

  2. Hi Kozley,

    To add more users (mailboxes), simply add them to the database you created or use SQL to insert them directly.

    Some examples…

    Adding a new mailbox for helpdesk@example.com with a password of helpme

    INSERT INTO user (email, password, name, quota, enabled) VALUES (‘helpdesk@example.com’, ENCRYPT(‘helpme’), ‘Example Helpdesk’, NULL, 1);

    Adding support@example.com as an alias for helpdesk@example.com (e-mails sent to support will be forwarded to helpdesk):

    INSERT INTO alias (source, destination, enabled) VALUES (‘support@example.com’, ‘helpdesk@example.com’, 1);

    Adding a new mailbox for a new domain info@examplenewdomain.com:

    INSERT INTO user (email, password, name, quota, enabled) VALUES (‘info@examplenewdomain.com’, ENCRYPT(‘helpme’), ‘Example Helpdesk’, NULL, 1);
    INSERT INTO domain (domain, transport, enabled) VALUES (‘examplenewdomain.com’, ‘virtual:’, 1);

    (Note that you need to add the new domain to the domain table).

    Let me know if you have any more problems.

    • But when I try to forward email from contact@.. to a second person, I get a Duplicate entry error. How can I manage to forward emails to many persons? Thanks

  3. Gday,

    Can you tell me how I I can forward mail using wildcards (if its even possible with this setup)?

    E.g. I want something like all mail coming from an email address with ‘twitter.com’ in the address gets forwarded to twitter@mydomain.com

    Cheers,
    Richard

  4. Man, you saved me! Thanks very very very much…
    I was trying to configure Postfix with all this stuff since 03/16

    Very good article…

  5. 1. If i don’t want to use ssl/tls , spamassasin,calmvs and amvis then how will the setting will look like?
    2. Is there no need for firewall setting?

  6. Is different system have different gid and uid? If yes how to find them?

    • Hi Krish,

      Sorry for the delay getting back to you. Are you still having problems? I’ll try my best to help you out.

      Adam

      • Yes, Adam

        I still have a problem . I’m getting frustated by searching internet and get all that same result.

        I use above setting but still am confused why my server is not working.

        By the way which user id and password while trying to login to the account created in the database.

        Krish

  7. when I try to restart postfix I get the following fail message:

    ———————————————————————————————————————–
    * Stopping Postfix Mail Transport Agent postfix postfix: fatal: /etc/postfix/main.cf, line 74: missing ‘=’ after attribute name: “smtp inet n – – – – smtpd”
    [fail]

    ———————————————————————————————————————–

    this is related to the Master Process configuration section above.

    ——————————————————————————————————
    #
    # Postfix master process configuration file. For details on the format
    # of the file, see the master(5) manual page (command: “man 5 master”).
    #
    # Do not forget to execute “postfix reload” after editing this file.
    #
    # ==========================================================================
    # service type private unpriv chroot wakeup maxproc command + args
    # (yes) (yes) (yes) (never) (100)
    # ==========================================================================
    smtp inet n – – – – smtpd

    ——————————————————————————————————————————-
    I don’t know why no one else has noticed this.

    • @rabbel you forget to add # on first line on /etc/postfix/main.cf.
      after you changes that and restart postfix the proble should be gone now ;)

      and one more question how about squirrelmail, because they use auth plain and cram 5 , can this tutorial working on that.

      Thanks sob for great articel.

      • I actually discovered I had copied configuration details to main.cf instead of to master .cf
        When I corrected that. I stopped having the errors I mentioned.
        Thanks for getting me to take a fresh look.

    • I was getting a similar error on startup:

      postmulti: fatal: /etc/postfix/main.cf, line 17-18: missing ‘=’ after attribute name: “??”

      It turns out that when copying/pasting the main.cf example, the blank lines (before and after the comments) had an extra character. Once I removed this character from every blank line, the service started without a problem.

  8. hola, I am trying to up a vmware with ubuntu 10.04 desckop mail server but have some problems with the virtual ip and some other configurations, does any one did it with a virtual machine and can say that this really works?

    thanks, Joan

  9. 2 questions

    1 How to I get thunderbird to get my mail. I have
    admin for user name
    admin@lbermudez.dyndns-free.com for email
    used “changeme” and “mailuserpassword” for password

    “thunderbird failed to find settings for your email account.” is the error i get.

    I have posted more details at
    http://ubuntuforums.org/showthread.php?p=11423216
    http://www.linuxforums.org/forum/ubuntu-linux/184177-postfix-thunderbird-help.html

    2 How do I add new user? I’m using ubuntu 11.10 and I need a step my step this is new for me.

  10. Error here:
    mv /etc/courier/imapd /etc/courier/imapd .default
    will be:
    mv /etc/courier/imapd /etc/courier/imapd.default

  11. Thanks a bunch. This is a great tutorial and it works. I tried flurdy’s before but didn’t work for me. I’ve found this one much better.

    I’ve followed exactly the same configuration as the tutorial with no problems and no errors. Then I’ve sent an email from my gmail account and I can read it when I connect through telnet. I mean (let’s say my server is mail.example.com):

    telnet mail.example.com 143 (WORKS OK)
    openssl s_client -connect mail.example.com:993 (WORKS OK)

    I can login and fetch the email I sent from my gmail account if I telnet to 143 or 993 ports.

    Now I’m trying to retrieve my email from Thunderbird 8.0. This is my account config:

    Server Name: mail.example.com
    Port: 993
    Connection security: SSL/TLS
    Authentication method: Encrypted password

    Then thunderbird says my server does not seem to support encrypted passwords and suggests to change to Normal password. If I do that, then thunderbird says Login Failed and invites me to enter another password.

    Can you point me in the right direction? Also, cat /etc/hostname shows the Amazon EC2 private dns. Should I change it to mail.example.com?

    Best Regards!

    • You should set Thunderbird to use “Normal password”, however, your credentials will still be sent encrypted by TLS/SSL to keep them protected.

      Have a look in your log files, they’re usually quite verbose so should be able to give you an idea where login is failing. In particular, check out /var/log/mail.err. There is more info in Flurdy’s guide on how to enable more verbose logging for authentication modules if needed. Feel free to paste logs here if you want some more help. Just be careful to remove anything sensitive first.

      The hostname in /etc/hostname should not affect your setup and I’d advise you don’t change it. The hostname in /etc/mailname, however, is more important and should be a publicly-resolvable FQDN (i.e. you should be able to ping the hostname from a machine outside the EC2 network).

      You could try overriding the hostname just for Postfix by adding the following line to the top of /etc/postfix/main.cf

      myhostname = mail.example.com

      I doubt, however, that this is the cause of your login problems. Best to have a look at those logs. Good luck!

      • I reinstalled the whole thing and it still fails in Thunderbird, but if I use Outlook instead, I can get mail from my server and send mail to my server. So it has to be something related to Thunderbird. Weird.

        But the big trouble now is when I try to send mail to gmail or hotmail, then I get the error “Relay access denied”.

        The /var/log/mail.log file shows

        postfix/smtpd[17958]: NOQUEUE: reject: RCPT from : 554 5.7.1 : Relay access denied from= to=” proto=ESMTP helo=

        There is nothing related to the problem in /var/log/mail.err

        Any ideas?

        Thanks a lot.

        • I see. My machine is a EC2 Amazon instance and it seems there are some issues related to reverse dns and this error.

          Thanks again for your tutorial. It’s very good.

      • Hello, Adam,

        can I use this tutorial to login to mail accounts using only TLS Certificiates? The idea is when i am on my pc i have already installed my X.509 certificate and i would like to login (using thunderbird) to my mail?

  12. Many thanks for this guide. I’ve been struggling to set up a fairly simple mail server for two days on my own, until finally giving up, and after a brief search for help, this post came up.

    I’m not sure where I was going wrong, but after a clear out and re-install, and following your instructions, we’re all up and running nicely.

    Cheers!

  13. Thanks for your excelent tutorial.
    Still, I have one question about what if I need that all users to be “real users”, with physical user accounts attached? (i.e. created by “adduser”)
    Is anything I should change/remove?

    Thank you verry much!
    Have a nice day!

  14. Hi, you have wrote a very good tutorial !

    I’ve found that All spam is directly deleted without any warning…even false positive mails…

    I’m just trying now to deliver all the spam in the spam-folder for every virtual user, which would be more safe.

    Could you please give me any advice for this setup ?

    Thanks a lot

    Spacio

    • Hi Spacio,

      That’s the behaviour expected using the configuration above. To tweak for your requirements, open up /etc/amavis/conf.d/50-user

      Then, add the following line:

      $spam_quarantine_to “spam\@mydomain.com”;

      You’ll need to make sure that the ‘spam’ mailbox exists, too. Just add a row in the ‘user’ MySQL table.

      Note that if a spam_quarantine_to value is provided, using final_spam_destiny = D_DISCARD will prevent the message arriving at the intended destination but a copy will be sent to the spam mailbox. I assume this is the behaviour you’re after.

      Good luck!
      Adam

      • Thanks Adam for this extra line of code, saved me hours of work!

      • What if you have more than one domain running on the mailserver?

        Then you can’t use $spam_quarantine_to “spam\@mydomain.com”; anymore…
        How do you cope with that?

        And how do I route the spam for a mailbox to a spam folder in that mailbox?
        So that every user for themself can see if the spam is really valid spam.

  15. i followed the guide to the word with the exception of substituting some areas with my name. when i went to test the settings in thunderbird all the info came up the way it was set up but the password could not be recognized and i went through all the instances in which mailuserpassword had to be changed if i could get some assistance

  16. Hi,

    I’m encountering a problem while trying to connect using thunderbird,

    the username and the password is invalid.

    I’ve tried with a new user but impossible to connect to the server…

    Can you please help me ?

  17. adduser clamav amavis
    rm -f /etc/amavis/conf.d/15-content-filter-mode
    vi /etc/amavis/conf.d/15-content-filter-mode

    had to modify this to:

    adduser clamav amavis
    rm -f /etc/amavis/conf.d/15-content_filter_mode
    vi /etc/amavis/conf.d/15-content_filter_mode

    and

    vi /etc/amavis/conf.d05-node_id

    mod;
    #$myhostname = “mail.example.com”;
    to;
    remove comment and add your FQDN

  18. hey, great howto :)

    but I got a Problem :( everything is great, but then comes a error when I want to connect with thunderbird “username or password invalid”.

    in log-files, these errors are shown:

    Disconnected, ip=[::ffff:87.181.121.99], time=1

    statistics: max cache size 2 at Mar 2 19:37:38

    statistics: max connection count 4 for (smtp:87.181.121.99) at Mar 2 19:37:38

    help me please ;)

    thanks :)

  19. Logging into admin@mydomain.com no problem.

    Created a new user with:

    INSERT INTO user (email, password, name, quota, enabled) VALUES (‘ric@mydomain.com’, ENCRYPT(‘blahblah’), ‘user’, NULL, 1);

    Attempted to login with squirrelmail and it failed.

    Looked at the /var/log/mail.log to find:

    chdir mydomain.com/ric/: No such file or directory
    ric@mydomain.com: No such file or directory

    I assuming the /var/spool/mail/virtual/mydomain.com/ric directory was not created because I do have an admin from the previous work we did.

    Is it as simple as creating a folder or do we need to do something else to get the proper directory structure? Maybe I missed a step?

    Thanks
    Ric

    • SOLUTION:

      You have to send your new account that was created an email from another account so that the directory structure gets created. Send a test message from an online email that you might have and after you should be able to login with:

      username @ yourdomain . com
      password

      Ric

      • Ric you are a star!

        This “how to” has worked really well but I needed this last bit to set up the directory structure.

        All is working now, thanks a million !!

  20. Hi ,

    I’m encountering the same problem as you with the password,

    Have you found a solution or else ?

    • I would look at your log file in one terminal prompt with this command:

      tail -f /var/log/mail.log

      Attempt to log in again with @.com through squirrelmail. If you get:

      chdir .com//: No such file or directory
      @.com: No such file or directory

      Then it would appear the folder structure for this account has not been created. I’m hoping someone has a solution and can share. It might be as easy as making the dir ourselves and the sub dirs will create themselves with courier/postfix? Not sure which one would.

      Ric

      • posted again because it didn’t like my “” references.

        I would look at your log file in one terminal prompt with this command:

        tail -f /var/log/mail.log

        Attempt to log in again with username @ yourdomain.com through squirrelmail. If you get:

        “chdir yourdomain .com/ username /: No such file or directory”
        “username @ yourdomain.com: No such file or directory”

        Then it would appear the folder structure for this account has not been created. I’m hoping someone has a solution and can share. It might be as easy as making the dir ourselves and the sub dirs will create themselves with courier/postfix? Not sure which one would.

        Ric

  21. Hi, i follow step by step the tuto, tuto very good work in local but i try to send out cannot with godaddy i am begginer in linux i try to help my company can you tell me if with your setting i can send out the email.
    Thanks in advance.
    Bruno

  22. Dear Friend,

    I done all the configuration but even i add user as it is showing up side . But when i login in SquirrelMail useing username = helpdesk and password = helpme . Giving me error unknown username and password incorrect . Help me .

    Thanks
    Jitendra Jha

    • If you took the example from Adam
      INSERT INTO user (email, password, name, quota, enabled) VALUES (‘helpdesk@example.com’, ENCRYPT(‘helpme’), ‘Example Helpdesk’, NULL, 1);
      your login will be helpdesk@example.com (replace example.com by the domain name that you created.
      Is just an idea.
      Thanks

  23. hello,

    very nice guide. but since im a newbie could anyone pls tell me 2 things ?

    1) how would i be able to add pop/imap email account on this postfix installation and set its email quota.

    2) im unable to see email send logs only pop logs are there in /var/log/mail.log

    Urgent help needed.

    Regards.
    Emad

  24. I tried this, and I can receive mail sent locally. But I can’t receive mail sent from the internet. Not sure why. It’s not hitting my server, as I see in the logs. I have an MX record configured.

  25. When i restart postfix i always get:

    /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: virtual_maildir_limit_message=”The user you are trying to reach has a full inbox. Please try again at another time.”
    /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: virtual_mailbox_limit_maps=mysql:/etc/postfix/maps/limit.cf
    /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: virtual_mailbox_limit_override=yes
    /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: virtual_overquota_bounce=yes

    what is wrong?

    • I have the exact same warnings, have you found a solution ?
      As anybody have a solution or knows why we have those errors ?

  26. While doing the upgrade to 12.04 LTS I received errors about upgrading the courier-pop-ssl and other ssl packages. The server still works after reboot. However, I plan to redo all the steps of the procedure to ensure no security holes are present.

  27. Hi Adam…
    are you still monitoring this page?

    I’ve tried your tutorial, at first I used mail address as “kodok.abc.com” (abc is my real domain name on the inet), edit my MX record in “my” web hosting via cpanel, and it worked perfectly.

    Then I changed mail address to “kodok@it.abc.com”, I also changed domain record in MySQL “domain” table. I’ve added sub domain it.abc.com in cpanel, redirect it.abc.com to my server (ip public), and assigned MX record for it.abc.com to my server. But now I only can send email to other server, and cannot receive any email (except from same domain – kodok2@it.abc.com).

    mail.log said “chdir it.abc.com/kodok/: No such file or directory”
    I’ve create manually same directory structure (copy from abc.com mail directory), but it can’t solve the problem…

    so.. is there any settings that i’ve missed?

    Thank you,

    Niksen H

    • Are you still getting any errors in the log?

      The best way to resolve missing directories is to send an e-mail to the new address, then try to connect to it. This method will ensure the directories are created with the correct permissions, owners and flags.

  28. Boniface Chacha

    May 13, 2012 at 7:35 am

    Hi,
    I am trying to connect to the new email i created but it fail to authenticate and in the log i see the following error:
    ..imapd: LOGIN FAILED, user=info, ip=[::ffff:41.222.183.45]
    ..postfix/smtpd[10340]: fatal: open database /etc/aliases.db: No such file or directory
    ..postfix/master[8833]: warning: process /usr/lib/postfix/smtpd pid 10340 exit status 1
    ..postfix/master[8833]: warning: /usr/lib/postfix/smtpd: bad command startup — throttling

    Can you please help me!

  29. Thanks a lot for a Link

    I am a new to this. I followed the link, exactly as you suggested and its work for me.

    My doubt, how should i proceed. How i am bale to login and send mails etc.
    I have no idea. can you please guide me.

    Thanks a lot in advnace

  30. Hello

    Also the authentication is ferom mysql.
    Is it possible to authenticate from Active directory server.

    Thanks a lot

  31. Hey, so I followed this guide on Ubuntu 11.10 x64 and the setup worked prefectly but I can’t connect a mail client to my system.

    I left the admin password as changeme, I keep getting configuration error, username / password returned.

    I have my DNS setup correctly because so far every mail client can find the two domain names for the mail server.

    I paste binned all the information to keep it clean, any idea whats going on.

    http://pastebin.com/zkke9tLy

    Great guide btw, first on that was good enough to ue!

  32. same problem on ubuntu 12.04 x64.And maby continue how-to how install squirlmail or roundcube :)

  33. Okay so I got past where I was, this is my updated config: http://pastebin.com/NzQV9z1n

    This is my mail log: http://pastebin.com/07cCejCM

    I can send mail but can’t recieve it, I can’t figure this out :-( any idea?

  34. Got it! I had to take reject out of the SMTP_RESTRICT, Once I took that out it worked.

  35. i try install squirlmaIl . but i cant login

    in /var/log/mail.err

    Jun 13 21:11:06 dimetil imapd: admin@dimetil.lv: No such file or directory

    and in in mail.log

    Jun 13 21:11:06 dimetil imapd: Connection, ip=[::ffff:176.9.207.173]
    Jun 13 21:11:06 dimetil imapd: chdir dimetil.lv/admin/: No such file or directory
    Jun 13 21:11:06 dimetil imapd: admin@dimetil.lv: No such file or directory
    Jun 13 21:11:19 dimetil imapd: Connection, ip=[::ffff:176.9.207.173]
    Jun 13 21:11:19 dimetil imapd: LOGIN FAILED, user=admin, ip=[::ffff:176.9.207.173]
    Jun 13 21:11:24 dimetil imapd: LOGOUT, ip=[::ffff:176.9.207.173], rcvd=44, sent=332

  36. Great short tutorial. I try it on Ubuntu 12.04 and it’s working. Great. Now stating resolve webmail setup :)

  37. Maybe add a “/et/intit.d/clamav-* restart” also.. Took me some hours to figure out that this was the reason that it could not find the user..
    (it defaults to run after reset, but I guess the reconfigure stops it.)

  38. Easy to follow HowTo, however I ran into the same problem as some others reported. Everything is configured accrodingly and I re-checked several times, looking for typos etc. The only thing I can think of is that there is some persistent previous setting that messes everything up. I am running MySQL 5.5 (latest) on Ubuntu 12.04 (up to date) and use MyPhpAdmin (It’s a lot easier to see things!). My tests from the localhost work fine, I can send mail from the console to an extern e-mail. Sending back causes a Reject e.g. my ISP is rejected from my Server. Setting up an e-mail account using “Thunderbird” fails too. Can’t verify the password or username! Seems as if it can’t connect/read the database? I am horsing for a long time around to find a HowTo that works, without success. I had it somewhat working before with dovecot and guess what? Dovecot decided to change their software, making it useless and leaving it krippled for me. By the time I get something to work, there is an update that pretty much destroys my work and I have to start from the beginning again. “Full time job to setup a mail server with MySQL”

    I have absolutely no clue why this HowTo fails?

    Cheers,
    Norbert

  39. Hi,

    After trying to restart postfix I get error message “postfix: fatal: /etc/mailname: cannot open file: No such file or directory”

    I probably missed something along the way but I don’t know what.

  40. Ok, I missed # ;)

    • Where did you miss the #?

      I’m getting the same error now. Looking through the two postfix conf files I don’t see any weird #s, and I copy-pasted it they all seem to be the exact same.

  41. Could you tell me how to configure the hostname and DNS for a server whose domain name is example.com

  42. after inserting users to mysql databse, i cant connect to imap. Log does not write anything. It just say wrong username or password.

  43. Dear all,

    First I would like to thank you for you tutotial.
    I have done all the steps stated on the tuto but I cannot connect any Mail client to the Mail server. When I try with Thunderbird, it keeps displaying cannot connect. I tried Evolution, nothing so far.
    Can you please provide which Mail client you have to use and also all the step for configuring that mail client.

    Thank you in advance.

  44. Ok, I have a fresh install of Ubuntu 12.04. I have this working on two 11.10 installs. I install this and I can send email just find but receive I get the following error. Any help or advice is greatly appreciated. Have a great week.

    Jul 13 19:40:12 mtbe postfix/smtpd[3798]: connect from imr4.er.com[196.34.60.90]
    Jul 13 19:40:12 mtbe postfix/smtpd[3798]: NOQUEUE: reject: RCPT from imr4.er.com[196.34.60.90]: 554 5.7.1 : Sender address rejected: Access denied; from= to= proto=ESMTP helo=
    Jul 13 19:40:14 mtbe postfix/smtpd[3798]: disconnect from imr4.er.com[196.34.60.90]

    IP’s and server names changed of course but other than that, exact.

    • Ok, on both my 11.10 and 12.04 servers my mail had stopped working on receiving email with error NOQUEUE: reject: RCPT from sender address rejected. I found a way to get it to receive emails but I had to change /etc/postfix/main.cf to the following:

      smtpd_sender_restrictions =permit_sasl_authenticated, permit_mynetworks,permit
      smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination

      Can anyone explain whey I had to change the last word to permit from reject to get this to work again. It worked before without any errors. Did normal updates from Ubuntu and it stopped working with the above error.

  45. Hi,

    Very good guide, thanks a lot.

    But I seem to have a problem. When I try to log in with chris@mydomain.com, I get the following errors in mail.log:

    Jul 14 03:21:16 5 imapd: Connection, ip=[::ffff:86.140.88.215]
    Jul 14 03:21:16 5 imapd: chdir mydomain.com/chris/: No such file or directory
    Jul 14 03:21:16 5 imapd: chris@mydomain.com: No such file or directory

    I don’t know why I can’t connect…

    I think mail is being delivered though. Where would it be stored?

    Thanks,

    Chris

  46. When i try to send mail from any of my computer which are in LAN. I get following error in error log

    Jul 14 14:52:49 fw5 postfix/smtpd[2640]: connect from unknown[192.168.1.104]
    Jul 14 14:52:49 fw5 postfix/smtpd[2640]: NOQUEUE: reject: RCPT from unknown[192.168.1.104]: 554 5.7.1 : Sender address rejected: Access denied; from= to= proto=ESMTP helo=
    Jul 14 14:52:49 fw5 postfix/smtpd[2640]: disconnect from unknown[192.168.1.104]

    Its not accepting mails from any user outside the network

  47. I tried to setup mail server on Ubuntu server following the tutorial. The tutorial is very clear and easy to follow and no issues or problems during the installation. But when I test the server, after installation, I kept receive the following login error:
    “pop3d: LOGIN FAILED, user=admin, ip=[::ffff:184.72.226.23]”

    I am quite sure that the password for admin is correct.

    Could anyone share alight what may go wrong?

  48. Hello,

    How someone can help me because I have followed this tuto step by step but when I try to log on to the squirrel mail app I can’t. Here are what I did :

    usename : admin@business.biz
    password: 1234578
    ERROR: Connection dropped by IMAP server.

    username: admin@business
    password: 1234578
    ERROR : Unknown user or password incorrect.

    Please help it is urgent & thanks in advance

  49. thanks for the tutorial. however, i cannot seem to connect with my client, thunderbird. i am getting the following error in /var/log/mail.log:

    Jul 20 10:03:12 la-xperience imapd-ssl: Connection, ip=[::ffff:xxx.xxx.xxx.xx]
    Jul 20 10:03:12 la-xperience imapd-ssl: couriertls: read: error:14094418:SSL routines:SSL3_READ_BYTES:tlsv1 alert unknown ca
    Jul 20 10:03:12 la-xperience imapd-ssl: Disconnected, ip=[::ffff:xxx.xxx.xxx.xx], time=0, starttls=1

    any ideas?

  50. Please let me know if you’re looking for a article writer for your weblog. You have some really good articles and I believe I would be a good asset. If you ever want to take some of the load off, I’d really like to write some content for your blog in exchange
    for a link back to mine. Please blast me an email if interested.
    Thank you!

  51. Hi Adam… sorry for late reply..
    finally i reinstall the server, start it again from scratch. Re-setting the router, then…
    whallaaaa it runs perfectly…
    thanks for this guide…
    it helped me much…
    thank you…

  52. Got it working without any problems. (reboot to make sure all services are started, use telnet to “send” a pop3 email to create directories.)
    What happened then was that it will work for approx 10-12 hours and then appear to freeze up.

    After some digging I found out that there is an error in the gam_server daemon.
    So if you kill this service, and everything is ok again do the following:

    Edit /etc/courier/imapd
    - Remove the word “IDLE” from IMAP_CAPABILITY
    - change IMAP_USELOCKS=1 to IMAP_USELOCKS=0

    This will probably only be a problem using thunderbird and IMAP

  53. Hey Adam,
    thank for this great guide. It works fine for me and my server ;-). I like your short and precise style because single settings can be looked up in the manuals.

    Good work! Thank you very much!

  54. my first email server ever.
    works like a charm after the initial mayhem.

    Thanks you very much for this perfect guide.

    my suggestion:
    this page – requires a forum.
    there are so many comments (82 including this).
    I don’t think comments are going to stop. :)

    what doesn’t work?
    what is the resolution?

  55. how to create more emails without sending a test email from another email server ?
    so that directories are created for someone to login ?

  56. Hello,

    How someone can help me because I have followed this tuto step by step but when I try to log on to the squirrel mail app I can’t. Here are what I did :

    usename : admin@business.biz
    password: 1234578
    ERROR: Connection dropped by IMAP server.

    username: admin@business
    password: 1234578
    ERROR : Unknown user or password incorrect.

    Please help it is urgent & thanks in advance

    • Try sending an email to that address from another email account like gmail or yahoo etc.
      I think the folders will not be created unless you do that.

  57. Hi Adam,

    Its realy need to install libauthen-sasl-cyrus-perl, If I use courier instead cyrus ?

  58. This is a great tutorial. Thanks for this. I’ve followed instructions and everything seems fine in my little Linode Ubuntu 12.04 box, which I’m using to host various sites. But, I’m sure my MX record is not right.

    What MX record(s) is needed to get this going?

    Thanks.

  59. Getting this in mail.log:
    Aug 8 23:29:29 churchnet postfix/smtpd[12218]: NOQUEUE: reject: RCPT from mail-wg0-f53.google.com[74.125.82.53]: 554 5.7.1 : Sender address rejected: Access denied; from= to= proto=ESMTP helo=

  60. Sorry. Got it. It was reverse DNS lookup tripping things. I’ve changed rDNS setting on Linode console and waiting for it to propagate…

  61. @Adrian – I think not just rDNS, because its needed to send email from your server to gmail. But in the record above you send mail from gmail to your server. May be you should see smtpd_recipient_restrictions variable in /etc/postfix/main.cf ( reject permit ) See variable value in http://flurdy.com/docs/postfix/

  62. Anyone want to help? I don’t see any replies lately. I still have this issue on both servers. Any suggestions?

    Aug 15 21:37:19 mtbexpert postfix/smtpd[9491]: NOQUEUE: reject: RCPT from qmta12.westchester.pa.mail.comcast.net[76.96.59.227]: 554 5.7.1 : Sender address rejected: Access denied; from= to= proto=ESMTP helo=

  63. Jason, try looking above in the comments at Jason Pate’s response – fixed it for me.
    Although I still have a problem with the creation of maildir when mails arrive.

    Aug 16 23:50:13 vps postfix/virtual[4653]: warning: maildir access problem for UID/GID=5000/5000: create maildir file /var/spool/mail/virtual/kvds.no/admin/tmp/1345153813.P4653.vps: Permission denied
    Aug 16 23:50:13 vps postfix/virtual[4653]: warning: perhaps you need to create the maildirs in advance
    Aug 16 23:50:13 vps postfix/virtual[4653]: CC2612FBF8: to=, relay=virtual, delay=0.07, delays=0.02/0.02/0/0.03, dsn=4.2.0, status=deferred (maildir delivery failed: create maildir file /var/spool/mail/virtual/kvds.no/admin/tmp/1345153813.P4653.vps: Permission denied)
    Aug 16 23:51:30 vps imapd-ssl: Connection, ip=[::ffff:79.161.94.116]
    Aug 16 23:51:30 vps imapd-ssl: chdir kvds.no/admin/: No such file or directory

    Not sure how I would go about solving this, so any tips is appriciated.

  64. Hi, I got the error info in mail.log:
    pop3d-ssl: couriertls: /etc/courier/pop3d.pem: error:02001002:system library:fopen:No such file or directory

  65. Hi! Very, very nice tutorial!
    I followed it exactly but I’m getting this warning (and some other) and don’t know how to fix that:
    “postfix/trivial-rewrite warning:connect to mysql server access denied for user mail@localhost /usingpassword yes”
    I tried the line:
    GRANT ALL ON mail.* TO mail@localhost IDENTIFIED BY ‘mailuserpassword’;
    with my current mysql password but no luck!
    Can someone help me out?
    Thanks!
    jimmi

  66. Hello,
    “One of the most fragile and fragmented services I’ve had to configure on Ubuntu is a mail server. No matter which of the many guides I follow, each time I do it there’s always something not working.”
    I could not agree more.

    This is my problem: I tried to setup logrotate to email me the log before it gets rotated. I tried to get mailx working but, when I test it, it will not send me the emails. I test it as follows:
    mail -s “Hello” myemailadress@gmail.com. It fails every time. Therefore, I think the problem is that I am lacking the email server.

  67. Think you very much for this tutorial, i have a problem same that:

    ERROR: Connection dropped by IMAP server.

    the following error in /var/log/mail.log:

    Nov 22 01:34:29 maiyn imapd: Connection, ip=[::ffff:127.0.0.1]
    Nov 22 01:34:29 maiyn imapd: chdir domain.com/admin/: No such file or directory
    Nov 22 01:34:29 maiyn imapd: admin@domain.com: No such file or directory

    thanks!

  68. Christopher Duff-harper

    December 6, 2012 at 11:12 pm

    I used this and it was very helpful but i came across an issue with receiving email from other servers such as gmail or yahoo. any ideas would be helpful.

  69. Hi Adom,
    Thank you for your tutorial.I still in a problem,i how can we create virtual users in the virtual mailbox table.
    my hostname is mail.server.com
    i expecting your repley

    thank you
    vysu

  70. Hi Adam,
    Hope you are still following this tutorial. I have followed your tutorial exactly without even changing the FQDN or password. I am establishing this email server for local network emails only and its not going to work on Internet. Unfortunately with evolution it still says user or password incorrect. I am new to linux.
    command hostname file returns: mail
    while hstname -f returns: mail.example.com

    Any advice will be highly appreciated.
    Regards,

  71. Love the guide, however, I followed it to the letter (minus the parts about changing things specific to me) and I’m running into some issues. The server has a static public IP, and the hostname of the server is set to ‘prodserv1′, and I have all of my mail configured to go to mail.mydomain.com (A Records and MX Records accordingly). I have a few issues, but I’m not sure if they’re related to one another.

    When I try to telnet on port 25 to the server, I get this output:

    220 mail.mydomain.com ESMTP Postfix
    EHLO mail.mydomain.com
    502 5.5.2 Error: command not recognized
    HELO mail.mydomain.com
    250 prodserv1.mydomain.com
    MAIL FROM:
    250 2.1.0 Ok
    RCPT TO:
    554 5.7.1 : Sender address rejected: Access denied

    Then if I try to have my mail client (Microsoft Outlook 2010) connect to it, I see the certificate error (since I used a self-signed certificate) but it can’t connect. I set it manually to use IMAP, and when I check /var/log/syslog, I get:

    Dec 26 22:52:24 prodserv1 postfix/cleanup[1806]: warning: connect to mysql server 127.0.0.1: Can’t connect to MySQL server on ’127.0.0.1′ (111)
    Dec 26 22:52:24 prodserv1 postfix/cleanup[1806]: warning: mysql:/etc/postfix/maps/alias.cf lookup error for “root@mail.mydomain.com”
    Dec 26 22:52:24 prodserv1 postfix/cleanup[1806]: warning: 3B3792488F: virtual_alias_maps map lookup problem for root@mail.mydomain.com — deferring delivery
    Dec 26 22:52:27 prodserv1 imapd: Connection, ip=[::ffff:74.136.188.186]
    Dec 26 22:52:27 prodserv1 imapd: LOGIN FAILED, user=MyUserAccountName, ip=[::ffff:74.136.188.186]

    I checked the configuration file for alias.cf, and it mirrors exactly what you have in your configuration, and I have confirmed that MySQL is running and accessible. Also, I’m not sure if I’ve configured things correctly, since I want the email addresses to be MyUserName@mydomain.com, the MX Records for mydomain.com should point to mail.mydomain.com, but I don’t want the e-mail addresses to be MyUserName@mail.mydomain.com.

    Any tips or advice would be appreciated!

    • I am also having the login failed issue over popd. I have combed through the logs, and this seems to be my only remaining issue. I am on ubuntu 12.04. I am trying to log in as the username (not the full email address). Even when i telnet in, it tells me login failed.
      Any thoughts?

      • Did you figure this out? I also get the mysql connection error with no logic reason:

        Jan 11 21:18:48 localhost postfix/cleanup[12846]: warning: connect to mysql server 127.0.0.1: Can’t connect to MySQL server on ’127.0.0.1′ (110)

    • I was able to fix the mysql connection error. It was caused by my iptables firewall rules. What I did was add the loopback access:

      iptables -A INPUT -i lo -j ACCEPT
      iptables -A OUTPUT -o lo -j ACCEPT

      still after that not working well, but it’s a progress

  72. mhh, keep getiing: “-ERR Temporary problem, please try again later” when i try
    netcat mail.example.com 110. any suggestions? ty for the guide btw!!

  73. I got my previous issue figured out – copy/paste issue. However, whenever I send an email, the from field only shows user@example.com. How do I set this up so the from field shows the user’s full real name?

  74. Yes finally got it working for receiving email. still get login error on sending.

    One of the things I had to do was follow the solution here: http://ubuntuforums.org/showthread.php?t=1277902

  75. Ok receiving works good. If the password is changeme, I enter that password and get access to the inbox.

    BUT when sending it’s like the encryption doesn’t work at all. In order to authenticate myself for sending email I have to enter the encrypted password (the result of ENCRYPT(“changeme”).

    It’s like that whole “pam” configuration from the tutorial doesn’t work. I have done exactly as explained in the guide.

  76. thanks I had a silly error in smtp.conf, had “check_” instead of “pwcheck_” at the beginning.

    I’m running into other issue now, the quotas I define in the DB are not respected. I read the unit there is bytes, so I set for instance a quota of 1 for a user, then send that user an email with a 8MB attachment, and the email is still received :s

    This means a spammer could overload the mailbox until my entire drive is full!!

  77. Hi Adam. Are you sure nothing else needs to be done with the quota field of the DB? In my installation it doesn’t respect the quota field at all. I’ve done the exact steps from the tutorial.. everything else works.

    • I’ve not actually tested the quota features as I don’t personally enforce them. However, I think I’ve found what’s missing.

      Please could you try the following and let me know if it works:

      1) Add the following lines to /etc/postfix/main.cf

      virtual_mailbox_limit_maps = mysql:/etc/postfix/maps/limit.cf

      2) Create a new file at /etc/postfix/maps/limit.cf with the following contents:

      user=mail
      password=ENTER PASSWORD HERE
      dbname=mail
      table=user
      select_field=quota
      where_field=email
      hosts=127.0.0.1
      additional_conditions=and enabled = 1

      3) Restart postfix

      Let me know how it goes. You may need to apply the VDA patch (http://vda.sourceforge.net/) and rebuild Postfix. I’m hoping that patch is no longer required…

  78. Thanks Adam for your response.

    I already got it fixed with help. Someone who helped me to fix this told me in Ubuntu the quota feature is not supported, so we downloaded the debian sources for Postfix, downloaded the patch from here: , rebuilt and then it worked.

    The steps I followed, in case it helps anyone:

    1-edit /etc/apt/sources.list and add:

    deb ftp://ftp.pucpr.br/debian wheezy main contrib non-free
    deb-src ftp://ftp.pucpr.br/debian wheezy main contrib non-free

    2-apt-get update

    3-cd /usr/src

    4-apt-get source postfix

    5-wget http://vda.sourceforge.net/VDA/postfix-vda-v11-2.9.1.patch

    6-cd postfix-2.9.3

    7-patch -p1 < ../postfix-vda-v11-2.9.1.patch

    8-vim debian/rules change export DEB_BUILD_HARDENING=0

    9-dpkg-buildpackage

    10- cd ..

    11- dkpg -i postfix-2.9.3-2.1_i386.deb

    12- dkpg -i postfix-mysql_2.9.3-2.1_i386.deb

    13- restart all services, for me this worked.

  79. OK, I can’t get this to work. I followed all the instructions and I’m quite happy that I did every step. I have added a new domain and a new user and I’ve double checked to see that they’ve made it into the database!

    I get the following error when trying to email:

    The error that the other server returned was:
    554 5.7.1 : Sender address rejected: Access denied

    Am I doing something stupid? Thanks in advance.

  80. Also, when I check the account in Outlook, I can’t logon – so i get the error:

    Log onto incoming mail server (POP3): Your e-mail server rejected your login. Verify your user name and password for this account in Account Settings. The server responded: -ERR chdir mydomain.com/info/ failed

  81. I am trying to get this emai to work and am getting the login issues. (access denied, server rejected login)

    does anyone have any solutions??

  82. hi dude….

    i am new in this email server setup…..i finished like ur procedure only but it did nt work in thunderbird…please help me..

  83. Hey Adam,
    Thanks for this great guide. It works fine.

    Good work!

    Dani

  84. Hi Adam, I followed you instructions to the book. Now i want to find out how i can make this mailserver a frontend to Microsoft Exchange. What it must basically do is forward all mails that it receives to an exchange server. You response will be appreciated.

  85. Thank you Adam for your excellent tutorials.

    I’ve followed through your tutorials and nearly get through with it. I can send out mail to my hotmail account from telnet. But I have problem receiving mails. It seems that postfix can’t connect to mysql to retrieve the virtual user information. Below is the tail of mail.log for your info:

    Feb 18 11:43:26 ip-10-130-71-35 postfix/qmgr[6335]: 2D05347E75: from=, size=1608, nrcpt=1 (queue active)
    Feb 18 11:43:26 ip-10-130-71-35 amavis[972]: (00972-01) FWD via SMTP: -> ,BODY=7BIT 250 2.0.0 from MTA([127.0.0.1]:10025): 250 2.0.0 Ok: queued as 2D05347E75
    Feb 18 11:43:26 ip-10-130-71-35 postfix/virtual[7176]: error: open /etc/postfix/maps/user.cf: Permission denied
    Feb 18 11:43:26 ip-10-130-71-35 amavis[972]: (00972-01) Passed BAD-HEADER, [113.173.10.137] [113.173.10.137] -> , quarantine: l/badh-lMhRvarfMvbi, mail_id: lMhRvarfMvbi, Hits: 2.287, size: 556, queued_as: 2D05347E75, 794 ms
    Feb 18 11:43:26 ip-10-130-71-35 postfix/smtp[7170]: 212A647E66: to=, relay=127.0.0.1[127.0.0.1]:10024, delay=2.6, delays=1.7/0.03/0.03/0.79, dsn=2.0.0, status=sent (250 2.0.0 from MTA([127.0.0.1]:10025): 250 2.0.0 Ok: queued as 2D05347E75)
    Feb 18 11:43:26 ip-10-130-71-35 postfix/qmgr[6335]: 212A647E66: removed
    Feb 18 11:43:26 ip-10-130-71-35 postfix/virtual[7176]: warning: mysql:/etc/postfix/maps/user.cf is unavailable. open /etc/postfix/maps/user.cf: Permission denied
    Feb 18 11:43:26 ip-10-130-71-35 postfix/virtual[7176]: warning: mysql:/etc/postfix/maps/user.cf lookup error for “myname@cuulong.vn”
    Feb 18 11:43:26 ip-10-130-71-35 postfix/virtual[7176]: warning: table virtual_mailbox_maps: lookup myname@cuulong.vn: Permission denied
    Feb 18 11:43:26 ip-10-130-71-35 postfix/virtual[7176]: 2D05347E75: to=, relay=virtual, delay=0.13, delays=0.03/0.02/0/0.08, dsn=4.3.5, status=deferred (mail system configuration error)

    Please could you or someone here help me out. I have been very desparate in finding a solution, but have reached no positive result yet.

    For your info: I am hosting this on EC2, Ubuntu 12.0.4 LTS. The rest is done as per this tutorial.

    Thanks.

  86. Hi dude, I hope this thread is still active. And hope that you can offer some help. I have a rather unforgiving and strange problem 1. I couldnt connect to the server with Thunderbird, I went though the comments, I sent an email through my google account with the hope that it will create a directory. I got no love from the server. Later I learned it could be something to do with the reverse DNS since I use linode, 28 hrs later – no love form the mail server. at one point i` had an access denoed, I tweeked the settings in main.cf as per the comments. now I send emails to the server, they dont get rejected, there is no directories created, the mail.log and mail.err are quiet as in there is nothing happening there. I dont know where to look next. can you help. I dont know if this will be useful but I can telnet into the server through ‘telnet server.com 25′

    I get

    onnected to stumphafe.com.
    Escape character is ‘^]’.
    220 machinename.localdomain ESMTP Postfix
    EHLO mail.server.com
    250-machinename.localdomain
    250-PIPELINING
    250-SIZE
    250-ETRN
    250-STARTTLS
    250-AUTH PLAIN LOGIN
    250-AUTH=PLAIN LOGIN
    250-ENHANCEDSTATUSCODES
    250-8BITMIME
    250 DSN

    what is the meaning of this

  87. Hi Adam firstly I appreciate your knowledge , I read this topic I need to try to configure it on my server ,before that I have some
    clarification or knowledge about domain setup who you set up your” mail.example.com” did you make example.com in your local machine .

    will you share your knowledge In mail pointing in our domain that we created in our lan ,if You do so more people include me will get clear clarification of how mail server work with domain

  88. I got it to work. I believe the “reject” is wrong in /etc/postfix/main.cf. I changed mine to “reject_unauth_destination.”

    The issue I am having currently is being able to use the SMTP server. I cannot seem to be able to send emails from other accounts to anywhere outside of my domain. Because of this I installed squirrel mail and it works wonderfully from there, sends and receives.

    I would like to get a SPAM folder though. I believe it was talked about in one of the higher comments and im gonna read that over again and give it a try.

  89. I got this error when starting courier-imap-ssl:
    “missinger IMAP-SSL server: ERROR – /usr/bin/couriertls”

    I got error starting courier-imap also. Something about umask 022, then I correct it changing the value manually in the script, changing the “umask $IMAP_UMASK” to “umask 022″, then I got another error about limit out of range, and then I change “ulimit -v $IMAP_ULIMITD” to “ulimit -v 65536″, and it works.

    Now I have no idea about error generated by courier-imap-ssl. The file /usr/bin/couriertls is there. Maybe the error is in script…

    Please, I need help here.

    • I solved the problem commenting those lines in the script courier-imap-ssl:
      #if ! [ -x $COURIERTLS ]; then
      #log_aciotin_msg “$PROGRAM: ERROR – $COURIERTLS missing”
      #exit 1
      #fi

      I then I had to change the values of $IMAP_UMASK and $IMAP_LIMIT manually also.
      It works now.
      But why the script has this erros?

  90. Hi Adam!

    Thanks a lot for this wonderful tutorial! I get everything working as intended, but I still have one problem left…

    I can’t see a Sent Folder in my mail client… Do I have to enable something first, or is it a preference set by the mail client?
    Thanks a lot :)

  91. After running the command on the next line i get the following error..”Permission denied”..CAN SOMEBODY PLEASE HELP??
    /etc/init.d/courier-authdaemon restart
    * Stopping Courier authentication services authdaemond /usr/sbin/authdaemond: line 16: /etc/courier/authdaemonrc: Permission denied
    [ OK ]
    * Starting Courier authentication services authdaemond /usr/sbin/authdaemond: line 16: /etc/courier/authdaemonrc: Permission denied
    [ OK ]

  92. wow.. I spent forever on this, but in your restart block at the end you need:

    /etc/init.d/courier-pop restart
    /etc/init.d/courier-pop-ssl restart

    or courier pop doesn’t pick up the changed certs and fails. FYI

  93. I try connect to smtp from remote host but i get:

    SASL CRAM-MD5 authentication failed: generic failure
    SASL LOGIN authentication failed: generic failure
    SASL PLAIN authentication failed: generic failure

    How to solve any ideas???

    • Take a look at your error log (/var/log/mail.log) for more details – should help identify what hasn’t been configured correctly.

  94. Your aproach for setting up things is the idea that Mysql should be installed.
    I have Mysql already installed so :

    apt-get install -y mysql-server postfix postfix-mysql libsasl2-modules libsasl2-modules-sql libgsasl7 libauthen-sasl-cyrus-perl sasl2-bin libpam-mysql clamav-base libclamav6 clamav-daemon clamav-freshclam amavisd-new spamassassin spamc courier-base courier-authdaemon courier-authlib-mysql courier-imap courier-imap-ssl courier-pop courier-pop-ssl courier-ssl

    It might work when the computer will not install things that are already installed.
    On the other hand I could type in everything execept mysql-server so you get:

    apt-get install -y postfix postfix-mysql libsasl2-modules libsasl2-modules-sql libgsasl7 libauthen-sasl-cyrus-perl sasl2-bin libpam-mysql clamav-base libclamav6 clamav-daemon clamav-freshclam amavisd-new spamassassin spamc courier-base courier-authdaemon courier-authlib-mysql courier-imap courier-imap-ssl courier-pop courier-pop-ssl courier-ssl
    What is the best to do?

    • Either will work – the apt-get tool will simply ignore packages which are already installed (unless the –reinstall option is provided).

  95. Kevin Holland

    March 9, 2013 at 3:51 am

    I followed your guide to the T on a brand new fresh ubuntu 12.10 instance and it refuses to work. When i send an email to the admin@ user that i created in your steps the logs output this..

    Sender address rejected: Access denied;

    I saw a few people mention to change the main.cf line from “reject” to “permit” but doing that only results in the following message in the error log….

    fatal: parameter “smtpd_recipient_restrictions”: specify at least one working instance of: check_relay_domains, reject_unauth_destination, reject, defer or defer_if_permit

    I’m stumped… anybody know how to get this thing working? I was so hopeful after spending all freaking day trying to get postfix working properly on an existing server i said screw it and started fresh with a new instance. le sigh

    • Kevin Holland

      March 9, 2013 at 6:35 am

      FYI, i just checked again with 12.04 and ran into the exact same behavior.Fresh install nothing else on it.

  96. Really great tut until it comes to the part where i get the errors :>

    Got everything working till it comes to connecting to the mail server via a mail client.

    I get errors of bad passwords and usernames but i can login perfectly from a webmail client that is local on the server.

    Any idea why i get these errors?

  97. ey bro i have this error

    Mar 11 17:00:01 new-SERVER postfix/smtpd[12161]: connect from localhost[127.0.0.1]
    Mar 11 17:00:01 new-SERVER postfix/smtpd[12161]: lost connection after CONNECT from localhost[127.0.0.1]
    Mar 11 17:00:01 new-SERVER postfix/smtpd[12161]: disconnect from localhost[127.0.0.1]

    u can helpme to solved that?

  98. hi! i need to redirect all mails like 1234@mydomain.com to admin@mydomain.com, can you help me!I know that it is possible to do a regexp aliases,but i don’t know how to set it, thanks

  99. Thank you for your tutorial ,it ‘s good .it worked perfectly.

  100. WARNING: The following packages cannot be authenticated!
    mysql-common libmysqlclient18 libnet-daemon-perl libplrpc-perl libdbi-perl
    libdbd-mysql-perl mysql-client-core-5.5 mysql-client-5.5
    mysql-server-core-5.5 mysql-server-5.5 libtommath0 libclamav6 clamav-base
    clamav-freshclam clamav clamav-daemon tcl8.5 expect courier-authlib
    courier-authdaemon courier-authlib-mysql courier-authlib-userdb gamin
    libgamin0 courier-base postfix courier-pop courier-ssl courier-pop-ssl
    db5.1-util libcompress-raw-zlib-perl libarchive-zip-perl libberkeleydb-perl
    libconvert-binhex-perl libio-stringy-perl libtimedate-perl libmailtools-perl
    libmime-tools-perl libconvert-tnef-perl libconvert-uulib-perl
    libcrypt-openssl-bignum-perl libcrypt-openssl-rsa-perl libdigest-hmac-perl
    libencode-locale-perl liberror-perl libhttp-date-perl libfile-listing-perl
    libfont-afm-perl libntlm0 libgsasl7 liburi-perl libhtml-tagset-perl
    libhtml-parser-perl liblwp-mediatypes-perl libhttp-message-perl
    libhtml-form-perl libhtml-tree-perl libhtml-format-perl
    libhtml-template-perl libhttp-cookies-perl libhttp-daemon-perl
    libhttp-negotiate-perl libio-multiplex-perl libsocket6-perl
    libio-socket-inet6-perl libnet-ssleay-perl libio-socket-ssl-perl
    libnet-http-perl libwww-robotrules-perl libwww-perl
    liblwp-protocol-https-perl libnet-ip-perl libnet-dns-perl libmail-dkim-perl
    libnetaddr-ip-perl libmail-spf-perl libnet-cidr-perl libnet-server-perl
    libpq5 libsasl2-modules-sql libsys-hostname-long-perl libunix-syslog-perl
    mysql-server pax postfix-mysql re2c db-util sasl2-bin spamassassin spamc
    amavisd-new courier-imap courier-imap-ssl libauthen-sasl-perl
    libauthen-sasl-cyrus-perl libpam-mysql
    E: There are problems and -y was used without –force-yes

  101. I cannot send email. Any replies would be appreciated.
    I have these settings that differ from the guide:

    postfix ==> local only
    127.0.0.1 wasis.co
    127.0.0.1 mail.wasis.co

    Then i send email from admin@wasis.co to helpdesk@wasis.co.
    *****************************************
    *These are some excerpt from mail.log:
    ****************************************
    Feb 19 14:28:49 laptop-cipto imapd-ssl: Connection, ip=[::ffff:127.0.0.1]
    Feb 19 14:28:49 laptop-cipto imapd-ssl: LOGIN, user=admin@wasis.co, ip=[::ffff:127.0.0.1], port=[42622], protocol=IMAP
    Feb 19 14:28:49 laptop-cipto imapd-ssl: LOGOUT, user=admin@wasis.co, ip=[::ffff:127.0.0.1], headers=0, body=0, rcvd=52, sent=156, time=0, starttls=1
    Feb 19 14:29:10 laptop-cipto postfix/qmgr[4267]: D97ED277AC: from=, size=525, nrcpt=1 (queue active)
    Feb 19 14:29:10 laptop-cipto postfix/qmgr[4267]: 01D742E330: from=, size=329, nrcpt=1 (queue active)
    Feb 19 14:29:10 laptop-cipto postfix/qmgr[4267]: A7B9B24137: from=, size=696, nrcpt=1 (queue active)
    Feb 19 14:29:10 laptop-cipto postfix/smtp[4520]: connect to 127.0.0.1[127.0.0.1]:10024: Connection refused
    Feb 19 14:29:10 laptop-cipto postfix/smtp[4522]: connect to 127.0.0.1[127.0.0.1]:10024: Connection refused
    Feb 19 14:29:10 laptop-cipto postfix/smtp[4522]: D97ED277AC: to=, relay=none, delay=69713, delays=69712/0.38/0/0, dsn=4.4.1, status=deferred (connect to 127.0.0.1[127.0.0.1]:10024: Connection refused)
    Feb 19 14:29:10 laptop-cipto postfix/smtp[4520]: 01D742E330: to=, relay=none, delay=67938, delays=67937/0.46/0/0, dsn=4.4.1, status=deferred (connect to 127.0.0.1[127.0.0.1]:10024: Connection refused)
    Feb 19 14:29:10 laptop-cipto postfix/error[4528]: A7B9B24137: to=, relay=none, delay=69596, delays=69596/0.57/0/0.04, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to 127.0.0.1[127.0.0.1]:10024: Connection refused)

    • Hey man not sure if you are still having the issue but its the content filter in main.cf that you need to edit. Comment out the line that says content_filter like below:
      # Force incoming mail to go through Amavis

      #content_filter = amavis:[127.0.0.1]:10024
      receive_override_options = no_address_mappings

      Chances are you might get spam but at least you can receive emails :)

      • I had this Connection Refused error. Kyle is correct; the content filter is the culprit. Hi suggestion will work, as it bypasses the content filter.

        My research led me to discover that this error is generally caused by amavis not starting. In my case it is because I did not specify matching FQDM in amavis config file:

        # amavisd-new start

        Gave me:

        WARN: running under user……
        The value of variable $myhostname is “xxxxx”, but should have been a fully qualified
        domain name…
        You must explicitly assign a FQDN of this host to variable $myhostname in
        /etc/amavis/conf.d/05-node_id …………

        Adding what I used to replace mail.example.com in the tutorial to the “$myhostname” variable in the above file allowed me to run:

        # amavisd-new start

        to successfully start the amavis service and resove this error.

  102. Hi Adam!

    First, I’d like to thank you for that tutorial very clear and that works (almost) perfectly!

    I recently chose to switch from a mutualized hosting offer to a VPS. Thought, I wanted to have a web and then a mail server running on it.
    Web server is up and running.

    For the mail server, thanks to your advices, it is up and half-running. My imap part is running now, thanks to the help of this comment http://www.pixelinx.com/2010/10/creating-a-mail-server-on-ubuntu-using-postfix-courier-ssltls-spamassassin-clamav-and-amavis/#comment-2007
    However, my smtp side isn’t working. As I had with imap, I have an auth error when trying to send a mail. And, as a newbie in mail server, I don’t know what’s going wrong…

    I’m using Thunderbird client to send a mail. Here is my main.cf if it can help you to point me out where to look : http://pastebin.com/xzvFRGHe

    Thank you in advance!
    Cheers.

    Romain

  103. Does not work for me. I am able to send emails from connected roundcube – this works fine.
    But I cannot send email from outside – I receive:

    Sorry, we were unable to deliver your message to the following address.

    :
    Remote host said: 554 5.7.1 : Sender address rejected: Access denied [RCPT_TO]

    Additionally when I try to send email from php I receive:

    Apr 2 12:28:13 server1 postfix/pickup[20342]: C29A076A833C: uid=33 from=
    Apr 2 12:28:13 server1 postfix/cleanup[20411]: C29A076A833C: message-id=
    Apr 2 12:28:13 server1 postfix/qmgr[20341]: C29A076A833C: from=, size=1440, nrcpt=1 (queue active)
    Apr 2 12:28:15 server1 postfix/smtp[20413]: C29A076A833C: to=, relay=gmail-smtp-in.l.google.com[173.194.65.27]:25, delay=1.2, delays=0.05/0.03/0.41/0.72, dsn=2.0.0, status=sent (250 2.0.0 OK 1364898494 f3si1493292eev.171 – gsmtp)
    Apr 2 12:28:15 server1 postfix/qmgr[20341]: C29A076A833C: removed

    What should I check / set ?

  104. Hi, first – I have to say ‘big thanks’ for that tutorial. It’s clean, I know (almost), what I’m doing.
    But after few hours of hard fighting, I’ve still 2 problems.

    1. Imap works fine, but I can’t login while sending email from thunderbird.
    SMTP configuraction is: Port: 465, SSL/TLS, normal (plain password).
    User -> like email in mysql, password -> crypted.
    After I’ve changed password to plain in database -> it works, but imap auth fails.
    It looks, like courier not setting crypting while login :(

    LOG:
    Apr 3 21:03:33 giana postfix/smtpd[2569]: connect from ip-XXX.XXX.XXX.XXX.XXXXX.XXXX.XXX[XXX.XXX.XXX.XXX]
    Apr 3 21:03:37 giana postfix/smtpd[2569]: warning: SASL authentication failure: Password verification failed
    Apr 3 21:03:37 giana postfix/smtpd[2569]: warning: ip-XXX.XXX.XXX.XXX.XXXXX.XXXX.XXX[XXX.XXX.XXX.XXX]: SASL PLAIN authentication failed: authentication failure
    Apr 3 21:03:37 giana postfix/smtpd[2569]: warning: ip-XXX.XXX.XXX.XXX.XXXXX.XXXX.XXX[XXX.XXX.XXX.XXX]: SASL LOGIN authentication failed: authentication failure

    2. It not delivering emails from other servers.
    For example, after sending an email from gmail, I’ve got message:

    Apr 2 22:37:49 giana postfix/smtpd[12013]: NOQUEUE: reject: RCPT from mail-lb0-f173.google.com[209.85.217.173]: 554 5.7.1 : Sender address rejected: Access denied; [...]

    • I had the same problems and could resolve them.

      1.
      First, be sure you are using the correct username, that is the email stored in the sql user table. So use ‘admin@example.com’ and not ‘admin’.
      After checking this, you should be able to recieve your emails from Courier. To send emails through smtp you have to disable the password encryption in the sql user table and replace the password by a plain text password, unfortunatly. Maybe there is a wrong setting in the smtp auth.

      2.
      In /etc/postfix/main.cf change those 2 lines:
      smtpd_sender_restrictions = permit_sasl_authenticated, permit_mynetworks, permit
      smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination

      Restart the deamons.

      Have fun.

  105. I read the whole tutorial and the comments. It made me curious suspicious if it would work for my setup haha. Maybe worth a try, I’ll let you know later.
    Thanks for your how-to!

  106. Hi Adam,
    this is my contribution back to this guide, and probably it will help people with errors trying to get email from outside.
    If you configure your local account from you LAN, it will be able to send and receive email but it won’t be able to get email from any other external email.
    In the configuration of the file: main.cf, section SPAM PREVENTION, it look like this

    smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject

    Probably this line is not complete but Adam may be you can check it. What I found searching in Internet is that we have to correct to this

    smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, rej
    ect_unauth_destination
    If you see at the end of the original line only reads “reject” but I replaced reject for ” reject_unauth_destination”. I was able to get email from anybody.

    I will be great Adam, if this correction is done to the guide.
    My mail server is working, able to receive email from anybody, I can send/receive from my smartphone too.

    Regards.

    Jos Pena.

  107. Hi guys,
    I have set up this mail server, works great to receive emails and to sen emails but i cannot send any emails externally to the network.

    error:
    NOQUEUE: reject: RCPT from **********: 554 5.7.1 : Relay access denied; from= to= proto=ESMTP helo

    I have checked the smpt with http://mxtoolbox.com/ and it appears fine all tickets.

    main.cf also as i read there are issues so changed to this from the start.
    smtpd_sender_restrictions =permit_sasl_authenticated, permit_mynetworks, permit
    smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination

    I am a little unsure what to check next.
    Cheers

  108. Hi all,

    Thanks a lot first, this guide is really great.

    I got the same problem as ric when trying to connect to a newly database-created user account : could not chdir ; his solution also worked (sent an email to that user and then I could see the directory structure created. So here are my questions :

    - What’s the point of not using real users if in the end we end up creating directories and files just the same (but inside /var/spool/mail/virtual …), which in fact makes us have to spit in an SQL request (and so long for my users possibility of changing their password or creating a new alias or mailbox… as well as webmin interaction…) ?

    - It’s a pain in the ass to have to send an email to any new user I create, why is that I have to do this, is it normal, and is there any way to avoid this ?

    Cheers
    Thomas

  109. Hi again :)

    Also, when I try to connect to the smtp from a mail client, using the database user I created, I get:
    postfix/smtpd[13611]: SSL_accept error from ASt-Lambert-153-1-50-252.w83-204.abo.wanadoo.fr[83.204.129.252]: lost connection

    Any idea where this comes from ?

  110. Thanks for your tutorial! Great work!

    But i got some errors on new mails
    postfix/smtp[6705]: connect to 127.0.0.1[127.0.0.1]:10024: Connection refused

  111. This tutorial is pretty much perfect but there is one thing that needs to be changed in an updated version and one caveat that people should keep in mind.

    First, in /etc/postfix/main.cf

    You should replace:
    smtpd_sender_restrictions = permit_sasl_authenticated, permit_mynetworks, reject
    smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject

    with:
    smtpd_sender_restrictions = permit_sasl_authenticated, permit_mynetworks
    smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination

    This should clear up issues regarding a “Relay access denied” error for RECEIVING emails.

    The second thing that nobody has been able to figure out so far is why some people are having issues SENDING mail and having their usernames and passwords fail on authentication. So, if you have gotten to this point and can receive email but SASL fails to authenticate you to send mail out, go check your mailuserpassword that you set for the mail database.

    If you used a # sign in your password for the mail account in mysql – PAM will shit the bed and error out because it thinks that the # in your password in /etc/pam.d/smtp is a comment and will ignore what follows. I repeat, DO NOT USE A # in the password for the mail@localhost mysql account!

    With these two things in mind, this tutorial works perfectly on Ubuntu 12.04 as of 24 April 2013.

  112. I’m stumped.

    Apr 25 11:36:02 ubuntu imapd-ssl: chdir ticktocktech.co.uk/admin/: No such file or directory

    The directory has not been automatically created. When I manually create it I receive a similar error stating the GUI or UID are incorrect. This is causing me to be unable to log in using any e-mail client. I have attempted to send an e-mail to the address however it fails to be delivered.

    • Michael Carthy

      April 26, 2013 at 2:02 am

      I’m posting an update for the benefit of others. For some reason the group ‘mail’ did not have write access to the /var/mail directory. So whenever a directory was attempted to be created, you’d see the error in my previous post. Once the group mail has been assigned write access to /var/mail – send a local e-mail to the e-mail address for the user you’ve created. That will automatically create the directory structure.

  113. i have followed your guide which worked perfect, butt i still have some problems.
    when i send a mail to my new created email address, it bounces and i receive a mail that delivery has failed. i have configured my dns records at my domain host. when i do a mx record check it is pointing to the correct IP address so i suppose it works. butt still i can’t receive any mail, and thus activate my account.
    hope you can help me

  114. Hi,

    Thanks for the tutorial – I am stuck while restarting courier

    /etc/courier/authdaemonrc: line 1: MYSQL_SERVER: command not found
    /etc/courier/authdaemonrc: line 2: MYSQL_USERNAME: command not found
    …..

    I double checked, the default file has tabs – tied that – did not work – googling got me to a page where dos2unix (new lines) fixed it but not for me –

    could you (anybody) please tell me what silly thing I am doing … ubuntu server 11.10 x 32

    Thx

  115. After upgrading to Ubuntu 13.04 I had errors where /etc/courier/pop3d.cnf and /etc/courier/imapd.cnf could not be read. I created those files with the following line:

    CN=mail.example.com

    and ran apt-get upgrade once again and things seem to be working again.

  116. Thanks a lot for this work!
    Now i managed to setup my own email server by using your knowledge you gave us.
    However my server does not receive any email from external. example when i use goolgle i receive an error msg says “there is a technical problem! DNS error!Domain name not found.
    Please help me to resolve this problem.

  117. very nice article/tutorial, straigh to the point everything works just fine for me with no problems. unlike other’s I saw on the net this one is more organized great work. :D

  118. OK it doesnt work error.log

    May 15 16:56:50 Leskow imapd: LOGIN FAILED, user=root, ip=[::ffff:127.0.0.1]
    May 15 16:56:55 Leskow imapd: LOGOUT, ip=[::ffff:127.0.0.1], rcvd=41, sent=332
    May 15 16:57:04 Leskow imapd: Connection, ip=[::ffff:127.0.0.1]
    May 15 16:57:04 Leskow imapd: LOGIN FAILED, user=info, ip=[::ffff:127.0.0.1]
    May 15 16:57:09 Leskow imapd: LOGOUT, ip=[::ffff:127.0.0.1], rcvd=41, sent=332M$
    May 15 16:49:53 Leskow postfix/master[12174]: terminating on signal 15
    May 15 16:49:53 Leskow postfix/master[12548]: daemon started — version 2.9.6, $
    May 15 16:52:53 Leskow imapd: Connection, ip=[::ffff:79.218.187.241]
    May 15 16:52:53 Leskow imapd: LOGIN FAILED, user=fabian-hagen, ip=[::ffff:79.21$
    May 15 16:52:59 Leskow imapd: Connection, ip=[::ffff:79.218.187.241]
    May 15 16:52:59 Leskow imapd: LOGIN FAILED, user=fabian-hagen, ip=[::ffff:79.21$
    May 15 16:55:59 Leskow imapd: Connection, ip=[::ffff:127.0.0.1]
    May 15 16:55:59 Leskow imapd: LOGIN FAILED, user=fh, ip=[::ffff:127.0.0.1]
    May 15 16:56:04 Leskow imapd: LOGOUT, ip=[::ffff:127.0.0.1], rcvd=39, sent=332
    May 15 16:56:11 Leskow imapd: Connection, ip=[::ffff:127.0.0.1]
    May 15 16:56:11 Leskow imapd: LOGIN FAILED, user=info, ip=[::ffff:127.0.0.1]
    May 15 16:56:16 Leskow imapd: LOGOUT, ip=[::ffff:127.0.0.1], rcvd=41, sent=332
    May 15 16:56:50 Leskow imapd: Connection, ip=[::ffff:127.0.0.1]
    May 15 16:56:50 Leskow imapd: LOGIN FAILED, user=root, ip=[::ffff:127.0.0.1]
    May 15 16:56:55 Leskow imapd: LOGOUT, ip=[::ffff:127.0.0.1], rcvd=41, sent=332
    May 15 16:57:04 Leskow imapd: Connection, ip=[::ffff:127.0.0.1]
    May 15 16:57:04 Leskow imapd: LOGIN FAILED, user=info, ip=[::ffff:127.0.0.1]
    May 15 16:57:09 Leskow imapd: LOGOUT, ip=[::ffff:127.0.0.1], rcvd=41, sent=332

    i dont no what to do im trying since days to rebuild my server it didn´t work one time!
    :(

    • U should try to login with “fabian-hagen@yourdomain.com” as user!
      The email address is the username. It took me one day to figure this out!

  119. Marius Odendaal

    May 20, 2013 at 4:10 pm

    Thanks for this great article. I helped me BIG time !

  120. Hello Adam,

    Thank you for the guide. I’m trying to itegrate postfixadmin into the management of the mail database, but i’m having the following errors in the process of transforming the database you suggested. If you can take some time to look into this and see if this is possible?

    I am following this guide: http://www.exratione.com/2012/05/a-mailserver-on-ubuntu-1204-postfix-dovecot-mysql/

    This is the error i’m getting at the bottom when running setup.php:

    Everything seems fine… attempting to create/update database structure

    Updating database:

    - old version: 2; target version: 740

    updating to version 3 (MySQL)…

    DEBUG INFORMATION:
    Invalid query: Unknown column ‘create_date’ in ‘alias’

  121. Ah, so I finally got sending to work after having the dreaded SASL Authentication failure message when trying to send main (receiving mail worked fine).

    All I did was run:

    adduser postfix sasl

    over agin. Before that I followed all the advice from Jos Pena’s comment.

    Of course I restarted all of the services – however, there are two services you should restart as well that helped me in the process:

    service courier-pop restart
    and
    service courier-pop-ssl restart

    Otherwise this is a brilliant article

  122. Hi Adam,
    I have already walked through your excellent guide. Great Job done!
    one question. Unfortunately my mail client cannot communicate to server via POP3/SSL (995).
    in mail log I have found:
    pop3d-ssl: couriertls: /etc/courier/pop3d.pem: error:0906D06C:PEM routines:PEM_read_bio:no start line
    Q: how shall I regenerate this file, that is empty but exists.

    Thank you!

    • Hi Adam,
      Issue solved. Please update your guide with this solution.

      the problem is the posfix is looking for the certificate in /etc/courier/pop3d.pem or imapd.pem.
      I have softlinked the host cert file, and the issue is fixed, everyone can connect to the mailbox through 995 port:

      # cd /etc/courier
      # ln -s /etc/ssl/private/”yourhostfqhn”.pem pop3d.pem
      # ln -s /etc/ssl/private/”yourhostfqhn”.pem imapd.pem

      no postfix restart required.

  123. Can you advise how to setup a smtp relay via gmail? I’ve used the config to setup my mail server and done some steps within the main.cf to add the relay however its not working & i’m getting rejection messages…

    Thanks

  124. Hi Adam,

    Two suggestions on your excellent guide:
    1. Build a variation using dovecot MTA.
    2. Add variations which would be compatible with likes of vimbadmin for domain/user management.

  125. running it for over a month now and WORKED perfeclty.
    since a few days i can’t connect to my mail server for outgoing mail. i can receive mail but i cant send it. in the log there are no errors indicating any problems. i’m hosting my server at a vps company and they do not block any ports. also the dns records are correct because it has worked. the error i’m having in my mail is error code 10600. any one who can help me?

  126. At 1. you have to configure courier to use clear text passwords, change in /etc/courier/authmysqlrc:

    MYSQL_CRYPT_PWFIELD to MYSQL_CLEAR_PWFIELD

  127. I tried and tried. First i found that the mail dirs are not created and i had to use maildirmake. Second, i had the problem with certificates, now with this:

    Jun 12 09:28:38 ip-172-31-12-116 postfix/trivial-rewrite[4552]: warning: connect to mysql server 127.0.0.1: Access denied for user ‘UNKNOWN_USER’@’localhost’ (using password: YES)
    Jun 12 09:28:38 ip-172-31-12-116 postfix/trivial-rewrite[4552]: warning: mysql:/etc/postfix/maps/domain.cf: table lookup problem
    Jun 12 09:28:38 ip-172-31-12-116 postfix/trivial-rewrite[4552]: warning: virtual_mailbox_domains lookup failure
    Jun 12 09:28:38 ip-172-31-12-116 postfix/trivial-rewrite[4552]: warning: mysql:/etc/postfix/maps/domain.cf: table lookup problem
    Jun 12 09:28:38 ip-172-31-12-116 postfix/trivial-rewrite[4552]: warning: virtual_mailbox_domains lookup failure
    Jun 12 09:28:38 ip-172-31-12-116 postfix/smtpd[4548]: NOQUEUE: reject: RCPT from mail-ie0-f173.google.com[209.85.223.173]: 554 5.7.1 :

  128. First, thanks Adam for a perfect tutorial :)

    I was having this issue:

    Jun 12 17:30:38 www postfix/smtpd[24126]: warning: SASL authentication failure: Password verification failed
    Jun 12 17:30:38 www postfix/smtpd[24126]: warning: unknown[80.227.150.102]: SASL PLAIN authentication failed: authentication failure
    Jun 12 17:30:42 www postfix/smtpd[24126]: warning: unknown[80.227.150.102]: SASL LOGIN authentication failed: authentication failure

    After hours of scratching head, I figured out mysql service wasn’t running. So I did:

    service mysql start

    and everything worked. I hope this helps someone else

  129. i checked my log, and i noticed this when starting/

    Jun 9 14:22:14 mail amavis[10341]: Amavis::DB code loaded
    Jun 9 14:22:14 mail amavis[10341]: Amavis::Cache code loaded
    Jun 9 14:22:14 mail amavis[10341]: SQL base code NOT loaded
    Jun 9 14:22:14 mail amavis[10341]: SQL::Log code NOT loaded
    Jun 9 14:22:14 mail amavis[10341]: SQL::Quarantine NOT loaded
    Jun 9 14:22:14 mail amavis[10341]: Lookup::SQL code NOT loaded
    Jun 9 14:22:14 mail amavis[10341]: Lookup::LDAP code NOT loaded
    Jun 9 14:22:14 mail amavis[10341]: AM.PDP-in proto code loaded
    Jun 9 14:22:14 mail amavis[10341]: SMTP-in proto code loaded
    Jun 9 14:22:14 mail amavis[10341]: Courier proto code NOT loaded
    Jun 9 14:22:14 mail amavis[10341]: SMTP-out proto code loaded
    Jun 9 14:22:14 mail amavis[10341]: Pipe-out proto code NOT loaded
    Jun 9 14:22:14 mail amavis[10341]: BSMTP-out proto code NOT loaded
    Jun 9 14:22:14 mail amavis[10341]: Local-out proto code loaded
    Jun 9 14:22:14 mail amavis[10341]: OS_Fingerprint code NOT loaded
    Jun 9 14:22:14 mail amavis[10341]: ANTI-VIRUS code NOT loaded
    Jun 9 14:22:14 mail amavis[10341]: ANTI-SPAM code NOT loaded
    Jun 9 14:22:14 mail amavis[10341]: ANTI-SPAM-EXT code NOT loaded
    Jun 9 14:22:14 mail amavis[10341]: ANTI-SPAM-C code NOT loaded
    Jun 9 14:22:14 mail amavis[10341]: ANTI-SPAM-SA code NOT loaded
    Jun 9 14:22:14 mail amavis[10341]: Unpackers code loaded
    Jun 9 14:22:14 mail amavis[10341]: DKIM code loaded

    does this has anything to do with my problem where i cant send e-mail?

  130. Adam,

    Thanks so much for taking your time to share this information with us. It is a great tutorial, and I learned a lot from it. THANK YOU!

  131. Hey there! I did all config and all appear to worked fine! When I try to connect (via thunderbird) I can’t go through the email account setup although I have configured all user/pass correctly and I see from the log that I am actually connecting

    Jun 25 07:00:45 localhost imapd: Disconnected, ip=[::ffff:84.189.180.137], time=0
    Jun 25 07:00:49 localhost imapd: Connection, ip=[::ffff:84.189.180.137]
    Jun 25 07:00:49 localhost imapd: Connection, ip=[::ffff:84.189.180.137]
    Jun 25 07:00:49 localhost imapd: Disconnected, ip=[::ffff:84.189.180.137], time=0

    any hint where/what to look for?

  132. Hi Bud, i have tried 6 times now to get postfix running without having any joy, seems like you know what your doing, I have a linux 12.04 ubuntu linode server. Would you like to set this up for me and i will pay you for your services. I have lost the will to live these past 2 weeks.

    Anytime i try set it up and then telnet mail.tobots.co.uk 25 i get connection refused, in /var/log/mail.log i getting some crap about an ai_socktype fatal: Fatal i belief is missing files, or info of some sort. Only message i getting.

    I will try your way this one time, if i have no luck joy i will let you know asap. lol

    ps
    Looks like a great set up.

  133. How to configure the email client to enter the mailbox? I am using Outlook but unable to connect.
    User information
    Your Name: Balint
    Email-address: admin@example.com

    Server Information
    Account type: POP3
    Incoming mail server: mail.example.com
    Outgoing mail server: mail.example.com

    Logon information
    User name: admin@example.com
    Password: changeme

    I also checked the ports with nmap (POP3: 110, SMTP: 25) which are set right.

    I left example.com here for reasons, but I have used my own domain of course. And what should I do with the user mail and the password mailuserpassword? I have done this the first time so I didn’t change them.

  134. By the way I checked the logs and there is an error saying couriertls: /etc/courier/pop3d.pem: error:02001002:system library:fopen:No such file or directory.

    I don’t have that file since we removed it, but I checked the /etc/courier/pop3d-ssl file which says TLS_CERTFILE=/etc/ssl/private/mail.dappwall.com.pem which exists.

  135. I have completed all this guide, but can i change the system mail name?

  136. Hi,
    Thank you, this guide help me alot. This server works on my apple-devices’s mail-client.
    The multi-domain feature does work too!

    However, I failed at the alias. I created an alias “helpdesk@example.com”, then created a mailbox name “bob@example.com”. When I sent a e-mail to helpdesk@example.com, it should be forwarded to bob@, however, I got a boundary “550 5.1.1 : Recipient address rejected: User unknown in virtual mailbox table”

    I dont get it, do I have to create a mailbox for helpdesk too? Since, I am using postfixadmin, it prevents me to make an alias and a mailbox with same name.

    Pleas help….

  137. heyyyyy, just completed the full guide, now, how can i sent an email using my mail server? how can i login? i’m a begginer, please answer me, its important :)

  138. If your using the lastest version of postfix and postfix admin, there is an error in his sql script in the alias field.

    use this instead.

    CREATE DATABASE mail;
    GRANT ALL ON mail.* TO mail@localhost IDENTIFIED BY ‘yourpassword’;

    FLUSH PRIVILEGES;
    USE mail;

    Create TABLE alias (
    address varchar(255) NOT NULL,
    goto text NOT NULL,
    domain varchar(255) NOT NULL,
    created datetime NOT NULL DEFAULT ’0000-00-00 00:00:00′,
    modified datetime NOT NULL DEFAULT ’0000-00-00 00:00:00′,
    active tinyint(1) NOT NULL DEFAULT ’1′,
    PRIMARY KEY (address),
    KEY domain (domain)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT=’Postfix Admin – Virtual Aliases’

    CREATE TABLE IF NOT EXISTS domain (
    domain varchar(255) NOT NULL default ”,
    transport varchar(255) NOT NULL default ‘virtual:’,
    enabled tinyint(1) unsigned NOT NULL default ’1′,
    PRIMARY KEY (domain)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;

    CREATE TABLE IF NOT EXISTS user (
    email varchar(255) NOT NULL default ”,
    password varchar(255) NOT NULL default ”,
    name varchar(255) default ”,
    quota varchar(255) default NULL,
    enabled tinyint(1) unsigned NOT NULL default ’1′,
    PRIMARY KEY (email)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;

    INSERT INTO alias (source, destination, enabled) VALUES (‘@localhost’, ‘admin@putyourdomain.com’, 1);
    INSERT INTO alias (source, destination, enabled) VALUES (‘@localhost.localdomain’, ‘@localhost’, 1);
    INSERT INTO domain (domain, transport, enabled) VALUES (‘localhost’, ‘virtual:’, 1);
    INSERT INTO domain (domain, transport, enabled) VALUES (‘localhost.localdomain’, ‘virtual:’, 1);
    INSERT INTO domain (domain, transport, enabled) VALUES (‘yourdomain.co.uk, ‘virtual:’, 1);
    INSERT INTO user (email, password, name, quota, enabled) VALUES (‘admin@putyourdomain’, ENCRYPT(‘soccer1971′), ‘Administrator’, NULL, 1);

  139. Marius Odendaal

    July 12, 2013 at 2:03 pm

    Quick question : Would it be possible to have a alias with a remote destination address?

  140. Marius Odendaal

    July 12, 2013 at 3:23 pm

    How to create a noreply@example.com

    Edit the /etc/postfix/aliases and added this: devnull: /dev/null
    Now run the command newaliases

    Insert your alias “noreply@example.com” account and make the destination devnull

    Hope this helps someone.

  141. Shouldn’t we change all instances of 127.0.0.1 to the IP of our server?

  142. Looks like a lot of people didn’t encountered the same login problem, same as me. And i don’t know what to do… =/

  143. after following the guide exactly and running “postfix check” , i recieve the following…
    (I do not understand how they could not be owned by root when root is root?!)

    Jul 17 10:50:35 johnsmith postfix/postfix-script[19410]: warning: not owned by root: /etc/postfix/maps/domain.cf
    Jul 17 10:56:02 johnsmith postfix/postfix-script[19532]: warning: not owned by root: /etc/postfix/maps/alias.cf
    Jul 17 10:56:02 johnsmith postfix/postfix-script[19533]: warning: not owned by root: /etc/postfix/maps/user.cf
    Jul 17 10:56:02 ProQuaerendumScientiam postfix/postfix-script[19534]: warning: not owned by root: /etc/postfix/maps/domain.cf

  144. I got through the entire tutorial, and on the last step I get the same errors as Renan above. I eliminated the first one the same way he did, but I have been able to find nothing to fix the second, the umask error.

    root@plato:/# /etc/init.d/courier-imap-ssl restart
    * Stopping Courier IMAP-SSL server imapd-ssl [ OK ]
    * Starting Courier IMAP-SSL server imapd-ssl
    : octal number out of rangel: line 90: umask: 022

    The settings in imapd-ssl are exactly has listed in the tutorial, and there is surprisingly little information on this error online. Have you any ideas?

  145. Hello Adam,

    Firstly, I would like to thank you very much for sharing this article and it is very useful for us ….

    Here, I am looking forward for your help to setup local a mail server (basically same server would not published to internet ) it is just used for users in a small office with LAN to communicated with email-IDs.

    Please guide me on same.

  146. the tutorial for me works well.
    I have a question if someone can help… how can I configure mailman to work?
    the standard guide doesn’t work because we have a sql configuration with postfix and a clamav installation…

  147. I followed this, and it seems to be working as far as I know. However, when I added my “admin” account, it starts updating (Using Android 4 by the way) and then says “Network Error”. No errors are shown in “/var/log/mail.log” either.

    Any ideas?

    Thanks.

  148. This tutorial works perfectly except that I can’t connect to the mail server with Thunderbird (all ports open), so it’s pointless without a complete guide how to properly set up a subdomain and the client to confirm how it’s supposed to work as a whole correctly.

  149. Hi,

    I did not try your guide out yet, but I will when I find time. I tried several guides on setting up my own email server to no avail. Your guide is definitely the most comprehensive at the same time readable and taking the shortcuts where it makes sense. If this works (and from the comments it seems it does) out of the box I will be genuinely impressed. Already by parsing the guide things start to make sense.

    Thanks for your work.

  150. I realize ric posted this on March 2nd 2012, but I just ran accross his same problem. It would be great if the original post could get updated. Even though it’s nearly 3 years old now, it is still a great guide. Just sucks to have a major piece of misinformation like that in it that completely breaks a large part of what is trying to be accomplished by the guide. Also, I know most people are going to be like me and not read through the comments to discover this problem before following the guide :(

    At the part where it tells you to edit the file 15-content-filter-mode, this is incorrect. The file name is 15-content_filter_mode. Also as ric stated in that same folder (/etc/amavis/conf.d), you will need to edit 05-node_id and uncomment the $myhostname line, then update it to your fully qualified domain name.

    If you follow the guide exactly at this part, your clamav, and your spamassassin will never as they are disabled in that file by default.

    • Thanks for the updates. I hope to update this guide soon so that it is compatible with 13.04.

      • Yeah, after doing some more research since posting last night and learning more about how these packages work. What you posted in the guide should have worked after all.

        It must’ve been another change that I made somewhere along the line that something else was preventing amavis from starting properly and I’m not sure what.

        If I understand it correctly, Amavis loads all files from the conf.d folder in alphabetic order. So it shouldn’t have mattered that the file was 15-content-filter-mode, it still should have enabled the loading since 15-content_filter_mode was simply all commented out and should not have effected it.

        Only thing I can think of is the 05-node_id is the more important change here, and it simply didn’t report the error initially, or reported it somewhere that I did not see it. I’d recommend in future guides to add the /etc/init.d/amavis restart to the list of restarts at the end of the guide. (I think it needed to be restarted anyway for the changes to the files in the guide to take effect).

  151. Hi Adam,

    Is there any way to have an individual Trash, Sent and Drafts mail folder for each user based on the server so my users mail is stored remotely? Also, is it possible to setup a Spam folder for each user just encase something gets put to spam when it shouldn’t be?

    Cheers Dan.

  152. Also, how can i configure postfix to allow mail to be sent from mobiles?

  153. Anybody able to use maildrop with the above configuration?

    main.cf
    maildrop_destination_recipient_limit = 1
    virtual_transport = maildrop

    master.cf
    maildrop unix – n n – – pipe
    flags=ODRhu user=virtual argv=/usr/bin/maildrop -d ${recipient}

    For command:
    maildrop -V 5 -d admin@example.com
    I get output
    maildrop: authlib: groupid=5000
    maildrop: authlib: userid=5000
    maildrop: authlib: logname=admin@example.com, home=var/spool/mail/virtual, mail=example.com/admin/
    maildrop: Changing to var/spool/mail/virtual
    maildrop: Unable to change to home directory.

    drwxr-sr-x 3 virtual virtual 4096 Aug 7 10:36 virtual

  154. When i try to add new mailbox

    INSERT INTO user (email, password, name, quota, enabled) VALUES (‘helpdesk@example.com’, ENCRYPT(‘helpme’), ‘Example Helpdesk’, NULL, 1);

    i get an error

    syntax error near unexpected token `(‘

    what i do wrong???

    • Stas,

      To add new users, you have to login to the mysql server first.

      On the command line type ‘mysql -uroot -p’ then enter your password.

      After you have logged in copy/type that command in again and it should work.

      Cheers Dan.

  155. i made as you said Dan and got another error
    ERROR 1046 (3D000): No database selected

    • On the command line type ‘mysql -uroot -p’ then enter your password.

      use mail;

      After you have logged in copy/type that command in again and it should work.

  156. Hi Adam,

    I got the maildrop working to filter the emails?

    Any idea or pointers how to create IMAP folders other than Inbox with your above configuration?

    Many thanks

  157. Hello!

    Thanks for the guide. I finally decided to start going through the pain of setting up a complete mail server. However, so far none of the guides I’ve found online (including this one) work in regards to SQL. MySQL spits out an error for every statement in the guide.

    “ERROR 1064 (42000): You have na error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘:’ 1)’ at line 1″

    It goes on like that for every statement. Am I doing something wrong with how I’m entering it? I’m starting to read through the MySQL manual now to see if I can debug it. Both copy/pasting it into the terminal or just manually typing it out in the blocks fails like that.

    Thanks for your help.

  158. I went through this guide quite successfully. I am currently awaiting my domain’s nameservers to propogate as well as my MX records to get added to the zone. However, I manually tested by putting in the IP address of my mail server and thus far I have been unable to successfully test using the admin@mydomain.com (replaced with my actual domain, of course) and the password I used.

    I have tried both the plaintext version of the password that I used while inserting the record into MySQL as well as the encrypted version that is currently in MySQL.

    Thunderbird keeps trying to auto set my settings to STARTTLS on port 143 for IMAP, instead of allowing me to use 993 with TLS/SSL.

    Do you have any suggestions and could there be a step I have missed?

    • Okay, so I have been able to get some progress.. I can receive messages, but I am unable to check the inbox for the account because I get login failed everytime I try to connect:

      Aug 15 17:48:48 slag imapd: LOGIN FAILED, method=PLAIN, ip=[::ffff:12.170.0.0]
      Aug 15 17:48:53 slag imapd: LOGIN FAILED, user=admin, ip=[::ffff:12.170.0.0]
      Aug 15 17:50:02 slag imapd: LOGIN FAILED, method=PLAIN, ip=[::ffff:12.170.0.0]
      Aug 15 17:50:08 slag imapd: LOGIN FAILED, user=admin, ip=[::ffff:12.170.0.0]
      Aug 15 17:50:19 slag imapd: LOGIN FAILED, method=PLAIN, ip=[::ffff:12.170.0.0]
      Aug 15 17:50:24 slag imapd: LOGIN FAILED, user=admin, ip=[::ffff:12.170.0.0]

  159. I’ve tested and I can login via imap and pop via localhost on the server. I cannot get it to work / connect to the inbox successfully for a user via imap-ssl / pop-ssl through a client such as thunderbird. I’ve made sure each account has an email in its inbox, but still nothing.. any help?

  160. I can’t connect from a client, the only error I et is this :

    imapd-ssl: Invalid port: /usr/bin/couriertls

    Do you know why ? It’s an actual error or just a message ?

    • I have the same error in /var/log/mail.log = “imapd-ssl: Invalid port: /usr/bin/couriertls”
      “netstat -atn” shows nothing listening on port 993
      The config file only refers to /usr/bin/couriertls in the COURIERTLS= section. the /usr/bin/couriertld file does exist.
      Has anyone been able to resolve this?

  161. Hi Guys
    I follow the instruction on a fresh Ubuntu 12.04 VPS and faced two things

    1- Error while postfix is trying to bind , so had to kill the below process
    #ps aux | grep mail
    #kill -9 “process ID”
    #/etc/init.d/postfix restart

    2- Not able to receive emails and changed to the following , which worked fine after that
    change /etc/postfix/main.cf to the following:

    smtpd_sender_restrictions =permit_sasl_authenticated, permit_mynetworks,permit
    smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination

    Now I am stuck with one problem , I can not send to Hotmail , I am getting below error
    any ideas will be great !!

    Note: I already updated the SPF

    Aug 18 10:33:49 q8marina postfix/smtp[15621]: smtp_connect_addr: trying: mx2.hotmail.com[65.55.92.184] port 25…
    Aug 18 10:33:50 q8marina postfix/smtp[15621]: mx2.hotmail.com[65.55.92.184]:25: EHLO q8marina.com
    Aug 18 10:33:50 q8marina postfix/smtp[15621]: < mx2.hotmail.com[65.55.92.184]:25: 250-SNT0-MC4-F13.Snt0.hotmail.com (3.18.0.72) Hello [192.3.95.176]
    Aug 18 10:33:50 q8marina postfix/smtp[15621]: < mx2.hotmail.com[65.55.92.184]:25: 250-SIZE 36909875
    Aug 18 10:33:50 q8marina postfix/smtp[15621]: < mx2.hotmail.com[65.55.92.184]:25: 250-PIPELINING
    Aug 18 10:33:50 q8marina postfix/smtp[15621]: < mx2.hotmail.com[65.55.92.184]:25: 250-8bitmime
    Aug 18 10:33:50 q8marina postfix/smtp[15621]: < mx2.hotmail.com[65.55.92.184]:25: 250-BINARYMIME
    Aug 18 10:33:50 q8marina postfix/smtp[15621]: < mx2.hotmail.com[65.55.92.184]:25: 250-CHUNKING
    Aug 18 10:33:50 q8marina postfix/smtp[15621]: < mx2.hotmail.com[65.55.92.184]:25: 250-AUTH LOGIN
    Aug 18 10:33:50 q8marina postfix/smtp[15621]: < mx2.hotmail.com[65.55.92.184]:25: 250-AUTH=LOGIN
    Aug 18 10:33:50 q8marina postfix/smtp[15621]: mx2.hotmail.com[65.55.92.184]:25: MAIL FROM: SIZE=2026 BODY=7BIT
    Aug 18 10:33:50 q8marina postfix/smtp[15621]: > mx2.hotmail.com[65.55.92.184]:25: RCPT TO:
    Aug 18 10:33:50 q8marina postfix/smtp[15621]: > mx2.hotmail.com[65.55.92.184]:25: DATA
    Aug 18 10:33:50 q8marina postfix/smtp[15621]: < mx2.hotmail.com[65.55.92.184]:25: 250 admin@q8marina.com….Sender OK
    Aug 18 10:33:50 q8marina postfix/smtp[15621]: < mx2.hotmail.com[65.55.92.184]:25: 250 ma7bob@hotmail.com
    Aug 18 10:33:50 q8marina postfix/smtp[15621]: < mx2.hotmail.com[65.55.92.184]:25: 354 Start mail input; end with .
    Aug 18 10:33:50 q8marina postfix/smtp[15621]: > mx2.hotmail.com[65.55.92.184]:25: .
    Aug 18 10:33:50 q8marina postfix/smtp[15621]: > mx2.hotmail.com[65.55.92.184]:25: QUIT
    Aug 18 10:33:50 q8marina postfix/smtp[15621]: < mx2.hotmail.com[65.55.92.184]:25: 250 Queued mail for delivery
    Aug 18 10:33:50 q8marina postfix/smtp[15621]: 9DE795A42E2: to=, relay=mx2.hotmail.com[65.55.92.184]:25, delay=1, delays=0.01/0.03/0.41/0.58, dsn=2.0.0, status=sent (250 Queued mail for delivery)

    also if anyone knowns how to make emails not to go to SPAM folder in GMAIL that will be a ++

  162. If you receive SSL_accept error when using Mail.app on Mac, it is because pop3d and smtpd certificates are different. Just open above generated .pem file in a text editor and use the same key/cert for smtpd

  163. Thanks very for this tutorial, i need help, i am trying to configure outlook client but i have authentication problem.
    Please can you help me in order to configure outlook client.
    thank in advance

  164. Thanks very for this tutorial, i need help, i am trying to configure outlook client but i have authentication problem.
    Please can you help me in order to configure outlook client.
    thank in advance

  165. hello Adam, I already have a LAMP installed on my developer machine,how can i proceed with the above process.
    iam planning to develop an app to send and recieve emails publicy.

  166. Hi Adam,
    i need an help, i can’t recieve email, /var/log/mail.err tell me no such file or directory, when i try to send email to admin@mydomain.com in order to create user mail directories, it take so long time and nothing happen, how can i do now?

  167. Quick question. Can i create a mail server with multiple domains?

    Like…

    john@foo.com and chris@bar.com can use my mail.blabla.com as mail server?

    How to set up other mail “domains”?

    Thanks for the post btw :D

    • Sure. Each domain you want to use must exist in the ‘domain’ table in the database. You then need to either add mailboxes by adding rows to the ‘user’ table, or create forwarding rules in the ‘alias’ table.

      Example SQL snippets are available in the ‘MySQL Database’ section.

  168. Hello, i was hoping you could help me figure this out,

    While connected to my local network everything works fine.

    But if i connect my computer over my 4g i can view / receive my email, but i cant send any out, it seems to connects fine with IMAP but it doesnt seem to work with stmp, the settings in Thunderbird are the same in both scenarios, so i dont think its an issue with the client

    ive also tried adding smtpd_client_restrictions = permit_sasl_authenticated to main.cf with no effect

    mail.log (example.com and x’s in place of actual names and ip’s)

    Sep 13 14:49:26 ubuntu-box imapd: Connection, ip=[::ffff:xx.xxx.xxx.xx]

    Sep 13 14:49:26 ubuntu-box imapd: LOGIN, user=admin@example.com, ip=[::ffff:xx.xxx.xxx.xx], port=[2658], protocol=IMAP

    Sep 13 14:50:02 ubuntu-box postfix/smtpd[20249]: connect from 34.sub-xx-xxx-xxx.myvzw.com[xx.xxx.xxx.xx]

    Sep 13 14:50:04 ubuntu-box postfix/smtpd[20249]: NOQUEUE: reject: RCPT from 34.sub-xx-xxx-xxx.myvzw.com[xx.xxx.xxx.xx]: 554 5.7.1 : Relay access denied; from= to= proto=ESMTP helo=

    but like i said this only happens when using a client that’s not on the same network as the server, but to send mail from clients on other computers on my network i had to edit mynetworks to 192.0.0.0/8 [::ffff:192.0.0.0]/104 [::1]/128

    so i think its something with sasl not authenticating, but i’m not sure.

    • Chris, see my comment below. If you have postfix version 2.10 or above, you need to add the following line to your main.cf -
      smtpd_relay_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination
      This will enable mail relaying to Connections that successfully authenticate through SASL

  169. I must say this is a very nice step-by-step tutorial to get everything you need on your LAMP stack at once.

    Minor flaw though, after running everything and carefully looking if I replaced everything necessary, it did not work. Now I’m clueless about where it went wrong and what pieces of this huge tutorial work on my server and which don’t.
    Time for a lot of debugging in everything together now, nevertheless its still faster then finding all this information myself :)

    Point of advice is adding some checks now and then to see if the previous “block” was executed correctly so we stay right on track.

    Keep up the good work, appreciated!

  170. I have the same chris’ issue

  171. I solved the issue adding

    smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination

    at the end of /etc/postfix/main.cf

  172. Adam,
    I followed this guide, and was able to get it all working (after starting amavisd), aside from being able to send emails to external addresses when connected from another host outside my network.
    After researching online, I found that Postfix version =>2.10 needs to have another line added to /etc/postfix/main.cf –
    smtpd_relay_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination

    Otherwise all attempts to relay email to an external address will fail.
    Might be worth adding to the guide, as well as a step to start amavisd?

    Hope this helps.

    • Hi Rob,

      I am having trouble amavis. Always displays ‘Connection refused’ when I try to fire it up.

      Can you guide me through the process of getting it to work?

      Thanks.

  173. Excellent Howto: I also ran into the need for the smtpd_relay_restrictions, I can send mail from an authenticated client now. Thank you.

    The issue I have seems to be with smtpd_sender_restrictions. Below is a reply mail from my hotmail to an email I sent from mydomain.com. Note Sender address rejected.

    Sep 18 10:01:38 mail postfix/smtpd[383]: connect from snt0-omc4-s44.snt0.hotmail.com[65.54.51.95]
    Sep 18 10:01:38 mail postfix/smtpd[383]: NOQUEUE: reject: RCPT from snt0-omc4-s44.snt0.hotmail.com[65.54.51.95]: 554 5.7.1 : Sender address rejected: Access denied; from= to= proto=ESMTP helo=

    smtpd_sender_restrictions = permit_sasl_authenticated, permit_mynetworks, reject

    I can comment out the smtpd_sender_restrictions and it works. I can also change “reject” to “permit” and it works. Neither seems an acceptable solution. Do I need the smtpd sender restrictions with spamassassin running? Suggestions?

  174. Great job,
    I did the previous guide and found it is wonderful HowTo. My current mail is mostly built like your guide.

    But, please, can you update how to make quota?

  175. Hi!
    Could you please publish proper Thunderbird settings which match this config?

  176. Hi, first at all THANKS. Very usefull guide.

    I’m new with this and I have some questions:

    How do I manage the accounts? (create user with password)
    To configure mi gmail account to download the emails (via POP) which port must I use? (110?)

    • I’ve just add the user with another insert INSERT INTO user (email, password, name) …

      but when I try to connect from my gmail account it shows me this error:

      “We were unable to locate the other domain. Please contact your other provider.”

    • I forgot to say that I’ve already added the mx record to my dns.
      Could it be due to the propagation? Or it is due to iptables issue someone talk some comments before.

  177. I love your how-to however my postfix does not work how it suppose to.

    If i comment out restriction to mynetwork etc then pop3 works but in other case i cannot send to and from the server. i have smaller version then 2 of postfix.

    Send me what info you need.

    From
    Attila

    • Its really wierd. I can recieve email if comment out those lines (restrictions) even though i have 2< version of postfix and if I try to add the lines mentioned above it does not recognize those commands. POP3 works fine without the restrictions but smtp doesnt. Any idea? I think I did everything mentioned above…

  178. Great guide!

    I’m almost there, I think. I’ve managed to get Thunderbird to autodetect my mail server, etc, but I’m getting an error when it’s attempting to test the username/password..

    “configuration could not be verified”

    I’ve tried using both ‘foo’ and ‘foo@bar.com’ as username (for my address foo@bar.com). None works. And I’m using STARTTLS and normal password.

    Any idea where things might go wrong? Is it possible to test the username/password locally on the server somehow?

    • Solved this, I accidentaly used the wrong password when creating the ‘mail’ user for mysql. Now I’m able to connect to both imap and smtp from thunderbird.

      BUT

      No e-mails are received:
      - I’ve tried to send an e-mail to myself using hotmail. But I receive the following message
      “: Sender address rejected: Access denied”

      No e-mails are sent
      - I can “send” emails using Thunderbird (no errors), but they don’t end up anywhere. I’ve tried e-mailing myself at foo@bar.com, and I’ve tried to send e-mail to my hotmail. Neither message is received.

      Any ideas? Another misspelling?

      • So, I’m looking in the mail.log (/var/log/mail.log) at one of my attempts to send an email from one of my e-mail accounts to another:

        Oct 9 14:53:14 ubuntu postfix/smtpd[18228]: connect from foo.foo.bar.bar[x.y.z.w]
        Oct 9 14:53:14 ubuntu postfix/smtpd[18228]: D70FAE1615: client=foo.foo.bar.bar[x.y.z.w], sasl_method=PLAIN, sasl_username=foo@bar.com
        Oct 9 14:53:15 ubuntu postfix/cleanup[18235]: D70FAE1615: message-id=
        Oct 9 14:53:15 ubuntu postfix/qmgr[18009]: D70FAE1615: from=, size=716, nrcpt=1 (queue active)
        Oct 9 14:53:15 ubuntu postfix/smtp[18223]: connect to 127.0.0.1[127.0.0.1]:10024: Connection refused
        Oct 9 14:53:15 ubuntu postfix/smtp[18223]: D70FAE1615: to=, relay=none, delay=0.24, delays=0.24/0/0/0, dsn=4.4.1, status=deferred (connect to 127.0.0.1[127.0.0.1]:10024: Connection refused)
        Oct 9 14:53:15 ubuntu postfix/smtpd[18228]: disconnect from foo.foo.bar.bar[x.y.z.w]
        Oct 9 14:53:20 ubuntu pop3d: Connection, ip=[::ffff:95.198.20.3]
        Oct 9 14:53:21 ubuntu pop3d: LOGIN, user=foo@bar.com, ip=[::ffff:95.198.20.3], port=[63615]
        Oct 9 14:53:21 ubuntu pop3d: LOGOUT, user=foo@bar.com, ip=[::ffff:95.198.20.3], port=[63615], top=0, retr=0, rcvd=12, sent=39, time=0, stls=1

        I believe the interesting part is the connection refused at “connect to 127.0.0.1[127.0.0.1]“, where amavis should be running. At least according to my main.cf file.

        ::/etc/postfix/main.fc::
        content_filter = amavis:[127.0.0.1]:10024

        But when I look for amavis in netstat I don’t find anything..
        root@ubuntu:~# netstat -tap | grep amavis
        root@ubuntu:~#

        So. Any ideas on how to get the Amavis instance to run properly?
        Or am I looking at this the wrong way?

        • Problem solved! I can send- and receive messages from admin@mydomain.com to info@mydomain.com using thunderbird!

          It turns out that Amavis wasn’t running. To get it running I had to follow these two steps:

          1) Edit /etc/amavis/conf.d/50-user
          sudo vi /etc/amavis/conf.d/50-user

          to add the following:
          $myhostname = ‘mail.mydomain.com’;

          2) Start the service
          service amavis start

          Don’t know if the service will start automaticly from now on. But at least it’s running for now.

          Still seeing a few errors in the mail-log though..

          Oct 9 15:37:07 ubuntu amavis[18659]: (18659-02) ESMTP::10024 /var/lib/amavis/tmp/amavis-20131009T153106-18659: -> SIZE=742 BODY=8BITMIME Received: from ubuntu.localdomain ([127.0.0.1]) by localhost (mail.mydomain.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP for ; Wed, 9 Oct 2013 15:37:07 +0200 (CEST)
          Oct 9 15:37:07 ubuntu amavis[18659]: (18659-02) Checking: J7zBVVuWgeRs [95.198.20.3] ->
          Oct 9 15:37:07 ubuntu amavis[18659]: (18659-02) ClamAV-clamd: Can’t send to socket /var/run/clamav/clamd.ctl: Transport endpoint is not connected, retrying (1)
          Oct 9 15:37:08 ubuntu amavis[18659]: (18659-02) (!)ClamAV-clamd: Can’t connect to UNIX socket /var/run/clamav/clamd.ctl: No such file or directory, retrying (2)
          Oct 9 15:37:14 ubuntu amavis[18659]: (18659-02) (!)ClamAV-clamd av-scanner FAILED: run_av error: Too many retries to talk to /var/run/clamav/clamd.ctl (Can’t connect to UNIX socket /var/run/clamav/clamd.ctl: No such file or directory) at (eval 100) line 375.\n
          Oct 9 15:37:14 ubuntu amavis[18659]: (18659-02) (!!)WARN: all primary virus scanners failed, considering backups

          Anyone had the same problem with the AV?
          As I’m able to send e-mails I’m not looking into it right now. Might do it later though..

        • I’m seeing the same errors with AV and cannot for the life of me figure this out. Have you made any progress. Error are as follows:

          Feb 2 15:24:28 SERVER-02 amavis[1556]: (01556-01) (!)ClamAV-clamd: Can’t connect to UNIX socket /var/run/clamav/clamd.ctl: No such file or directory, retrying (2)
          Feb 2 15:24:34 SERVER-02 amavis[1556]: (01556-01) (!)ClamAV-clamd av-scanner FAILED: run_av error: Too many retries to talk to /var/run/clamav/clamd.ctl (Can’t connect to UNIX socket /var/run/clamav/clamd.ctl: No such file or directory) at (eval 100) line 375.\n
          Feb 2 15:24:34 SERVER-02 amavis[1556]: (01556-01) (!!)WARN: all primary virus scanners failed, considering backups

      • “Sender address rejected: Access denied” check your postfix configurate file: main.cf

        Look closely to the “#Basic spam preventions” this is the root of your problem. My configuration is slightly different from the guide, but it works.

        # Basic SPAM prevention

        smtpd_helo_required = yes
        smtpd_delay_reject = yes
        disable_vrfy_command = yes
        smtpd_sender_restrictions =
        permit_sasl_authenticated,
        permit_mynetworks,
        reject_unauth_destination,
        permit
        smtpd_recipient_restrictions =
        permit_sasl_authenticated,
        permit_mynetworks,
        reject_unauth_destination,
        permit

        smtpd_relay_restrictions = permit_mynetworks,
        permit_sasl_authenticated,
        reject_unauth_destination

  179. Plese make video of installation and webmail (http://rainloop.net/)

  180. Excellent tutorial, thank you!!

    I’d love to see it fleshed out a little more with details on how to test the configuration (i.e. sending and receiving an email using the mail server) and also how to add new users (it looks like we’ve created admin@example.com, but how do i check admin’s emails?!) . Also some info on amending MX DNS records to make the whole thing work would be useful.

    Thanks again for helping me get this far anyway.

    David

    • I managed to get it all working. To help others here are a few tips.

      1) Make sure you start Amavis and also add the smtpd_relay_restrictions config to main.cf as detailed by others in the comments above. You’ll also need to amend sender and recipient restrictions to permit external mail.

      2) To add users you need to add them to the mysql mail database. This can be done by adding to the database config you entered previously.

      e.g.

      mysql -u root -p
      use mail;
      INSERT INTO user (email, password, name) VALUES (“newuser@example.com”, ENCRYPT(“newuser password”), “New User”);
      quit;

      **amend newuser as appropriate and example.com

      3) You’ll probably also need to create the directory structure as Courier didn’t do this for me automatically.

      mkdir -p /var/spool/mail/virtual/example.com/newuser{new,tmp,cur}
      chown -R virtual:virtual /var/spool/mail/virtual/example.com/newuser/

      ** amend newuser and example.com as appropriate

      4) You can see if the config is working by using sendmail and watching the ‘/var/spool/mail/virtual/example.com/newuser/new’ directory. You should see emails being generated and be able to look at them using cat. If it doesn’t work check /var/log/mail.log to see what is happening.

      5) To access and send email of the virtual users you can use Thunderbird on your home PC/Mac. These account settings worked for me:

      Server Name = mail.example.com
      User Name = newuser@example.com (i’m not sure if you need the @example.com so try without it if it doesn’t work)
      Protocol = IMAP
      Security = SSL/TLS
      Authentication = Normal Password
      Port = 993

      For SMTP use SSL/TLS, Normal Password and 465

      Note that you will need to make sure that these ports are open on your server firewall. Add ACCEPT rules to IPTABLES if not.

      If you are having issues with Thunderbird you can enable logging and view the logs when sending/receiving email.

      6) If you are still having issues double check that you have copied/pasted all of the tutorial config correctly. My /etc/pam.d/smtp file already had some config in. I foolishly left it and it took me a lot of troubleshooting to realise that it was causing an issue.

      7) After you’ve got it working use mxtoolbox.com to make sure that you haven’t setup an openrelay or that your mailserver is blacklisted

      8) I forgot to mention that you also need to make sure that your DNS and MX records are setup correctly. You need to add an A record pointing to the IP Address of mail.example.com. And then add an mx record for the .example.com domain pointing to mail.example.com. DNS records may take 72 hours to update across the Internet so be patient. You can always use ping and whois and other tools to see if the updates have been applied yet.

      9) Good luck and don’t give up. It’s pretty sweet having the control of your own mail server once it is setup and by troubleshooting the config you learn how it works.

  181. Just wanted to pop a comment on here and say a HUGE thank-you to Adam for this amazing guide, it’s been an absolute god send.

    I worked through it completely with my server, and now for the first time, I have access to emails on every domain I own! Ha, a small step for some, but for me it’s a huge achievement – so many many thanks.

  182. In the MySQL configuration:
    GRANT ALL ON mail.* TO “mail”@”localhost” IDENTIFIED BY “mailpassword”
    I get the following problem: ACCESS DENIED FOR root@localhost (USING PASSWORD = YES)

    The MySQL-server only works when the –skip-grant-tables option is activated. So when I try to login without this option, I get an error. Now my problem is: How can I still run this command to use a mail server???

  183. Hi,

    First off, thank you for the guide and all the time you invested in it. It’s been extremely helpful.

    I have a very (more than likely) simplistic question that either you or someone else may answer:

    I want to forward all mail sent to root@myserver.com to user@myserver.com. I’ve attempted simply editing /etc/aliases but it doesn’t seem to work. Am I missing something?

    Thank you again.

    • I have the same issue. Did you figure it out? mail for root@mail.example.com bounces as the configuration only accepts email for example.com. Same for email sent to www-data@mail.example.com. Therefore, I need to forward this mail to admin@mail.example.com

    • To forward local email sent to root or www-data to the admin account just do:

      mysql -uroot -p
      USE mail;
      INSERT INTO alias (source, destination) VALUES (“root@mail.example.com”, “admin@example.com”), (“www-data@mail.example.com”, “admin@example.com”);
      quit;

      It will only forward local email. If you send an email from external source to root@mail.example.com it will not redirect as the settings only allow email to @example.com

  184. I tried to install the POSTfix , after Installed i checked the Status using
    sudo postfix status after getting

    postfix/postfix-script: the Postfix mail system is not running

    Please advice me

  185. Very nice step-by-step tutorial.
    My telnet-test works fine :D But I can’t login with Thunderbird. The username or Password is wrong.. I have to use the data from my MySQL-Table, right? So the username is ‘Administrator’ and the proper password… I tried very much combinations, but everytime the same error.
    Have someone any idea?

    • I am having the same issue. It detects my email server and Thunderbird says “Connected to mail.mywebsite.com” but it keeps asking for a different password. I have created and tried several different accounts and passwords through MySQL and created a directory structure, but none of that seems to matter. I appended the fixes to the end of main.cf and followed all of David’s recommendations above.

      I can send emails to my accounts and they seem to go through, though nothing is appearing in the virtual user folders on the server. So there’s something wrong. I just can’t for the life of me figure out what. The installation went through without any errors, step by step.

      • Okay, I fixed the login issue. I miscopied something in /etc/courier/authmysqlrc so make certain all of those MySQL settings are correct.

        I can now add all of my email accounts to Thunderbird without an issue and it’s actually started to autodetect settings. The only remaining problem is sending/receiving emails as nothing I send to these addresses appears in the Inbox and attempting to send an email in Thunderbird presents this message:

        Sending of message failed.
        The message could not be sent because the connection to SMTP server timed out. Try again or contact your network administrator.

        One last thing to figure out.

  186. How can we backup our saved mails ?

    They are not stored in DB ? Is there any other option then tar.gz the ‘new’ directory

  187. is this guide compatible with ubuntu 10.04

  188. is this guide compatible with ubuntu 10.04

  189. hey i already have mysql installed ,what do i do to install the rest at a go

  190. HI Adam,
    i have MySqlversion 5.1 installed.Please tell me where I can start from the above process.
    from the very start,what can I adjust in the installation you gave above?

  191. I came across this note in the procedure above:Make sure you have this subdomain configured in your DNS records.

    but in my case iam on a developer machine with no registered domain name,iam just trying to send out mail from my machine to other mail clients on line like yahoo,can i put any name here
    like shad.com OR IT IS NOT POSSIBLE?

  192. HOW CAN I MAKE A DNS .since iam on a stand alone/remote machine and access internet on a dongle

    • If you are using a 3G or other dongle the chances of you having a static IP address are slim, which for outbound mail is rather important. You also tend to find that IP address for these type of connections (and many fixed connections too that run DHCP allocations) are listed in blacklists as they shouldn’t be used to send mail.

  193. Just a note, you’ve updated this for Ubuntu 13.04 however as from the 27th Jan 2014 it (13.04) will be end of life and no longer get security patches. For important things like server people really should be using the LTS releases (https://wiki.ubuntu.com/LTS) which continue to get supported updates (security and otherwise) for 5 years rather than the 9 months of the non-LTS releases.

    So if you’re looking for a long term supported system without so much pain from do-release-upgrade you might want to stick with 12.04 for now :)

  194. Great tutorial Adam! The only question that I have and that it might be nice to add to the tutorial is how to add an account like no-reply@example.com that goes to /dev/null or that sends a response to the sender saying “This address does not accept mail” or something like that.

  195. Hi there. I have a big problem.

    So email user: user@domain.com and password pass007

    When i loggin in just: user@domain.com and pass without 007.
    What a problem?

  196. Hey.

    Great guide, finally set up my own mail server.
    I’ve used the mail app on my mac (OS X Mavericks) to connect to my new e-mail on the mail server and it receive mails just fine, but when i try to send mails nothing happens. In the mail log (/var/log/mail.log) on the server it says that:
    “SSL_accept error [IP]: lost connection

    Any advice as to what i need to edit/fix to make it work?

  197. Thank so much you detail howto, I follow howto and config Ok on debian 6
    To get auto create imap folder working for new user i have to make some change as

    #chown virtual:postfix /var/spool/mail/virtual/demo.com
    #chmod 775 /var/spool/mail/virtual/demo.com

    and edit: /etc/courier/imapd with IMAP_MAILBOX_SANITY_CHECK=0

    #service courier-imap restart
    #service courier-imap-ssl restart

    When add new user i just create new user vi mysql and send one email to that user and that will be OK.

    I just wonder if this is a bad security issue since all auto create imap folder will change group owner by group postfix

  198. Hey! nice guide dude, so many thanks, I added to my fav list :P

  199. Whats the best way to test all the installed programs and components?

  200. hey! i’ve followed all of your instructions, now i’m trying to use java to send a mail via my configured server, but somehow i always run into a 535 authentication failed-exception. my code looks like this: http://pastebin.com/mEbAAV2c
    of course i replaced example.com with my fqdn, and i tried “Administrator” as well as “mail” as usernames. do i miss something?

  201. Hi and thanks for the tuto. Someone can tell me how to delete users in the mysql “user” table.
    I mean I used the given syntax (INSERT INTO user …) to create many test users and I want to delete these users.
    Thanks

  202. A huge thank you. Wanted to ask if you have additional instructions for postfix admin based on the details you provided here. Out of all things linux, mail servers is the one thing I have a challenge with.

    Many thanks, dvr

  203. I followed your tutorial but getting error

    SASL LOGIN authentication failed: authentication failure

  204. Hello All,

    I’m really new on Nagios. Hope someone will help me and figured out why i got an error, When I “service postfix restart”:

    fatal:/etc/mailname: file has 2 hard link

    I got stuck on this issue.

    Thank you in advance for all the reply.

  205. Hello All,

    Great Guide ! Thank you so much.

    Everything is working fine for me so far.

    Although i cant send emails from e.g. googlemail to my mailserver.
    I get an access denied error.

    When i switch my main.cf
    smtpd_recipient_restrictions =permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination,permit

    Last Line: (reject to permit) -> i can recieve mails from googlemail , hotmail , …
    But this seems to be not acceptable as it opens a bit too much i guess ?

  206. pam_mysql.so support is now dropped (see http://serverfault.com/a/579225), apparently pam_mysql module has not been updated for quite some time. Looking to solve this some way atm, as my customers can’t send mail right now. This happened me with Ubuntu 12.04 LTS, with an system update (which seemed a bit odd as I did NOT do apt-get dist-upgrade).

    Just to get some SEO attention I’ll post here some lines from /var/log/auth.mail:
    Mar 7 20:04:44 myserver saslauthd[29018]: PAM unable to dlopen(pam_mysql.so): /lib/security/pam_mysql.so: undefined symbol: make_scrambled_password_323
    Mar 7 20:04:44 myserver saslauthd[29018]: PAM adding faulty module: pam_mysql.so
    Mar 7 20:04:44 myserver saslauthd[29018]: DEBUG: auth_pam: pam_authenticate failed: Module is unknown
    Mar 7 20:04:44 myserver saslauthd[29018]: do_auth : auth failure: [user=user.name@example.com] [service=smtp] [realm=example.com] [mech=pam] [reason=PAM auth error]

    • Problem solved , my own bad.

      I were using MariaDB (through MariaDB’s own repositories) and apt-get update did not honor distro depedencies, and thus picked up a version which had dropped support for pam_mysql. Removing MariaDB and installing MySQL was a hassle, but solved the problem.

  207. Hello all,

    I need to find some attachments which sent to a mailbox of a user. I also tried to issue find / -name “abc.jpg” but it didnt find.

    How can I find the attachments which sent to the user ?

    Thanks

  208. Hello,

    How can I set a catch-all email?
    I’ve tried to add record to alias @domain.com -> admin@domain.com but it didn’t worked. I received response email saying that the email was not delivered.

  209. Hi everybody,
    like someone I also can’t figure out how to solve the:
    “SASL LOGIN authentication failed: authentication failure” error returned while trying to connect to the smtp and send a mail. My auth.log file contains:

    Mar 21 15:10:18 cosmonet postfix/smtpd[7505]: commit transaction
    Mar 21 15:10:18 cosmonet postfix/smtpd[7505]: sql plugin Parse the username admin@example.com
    Mar 21 15:10:18 cosmonet postfix/smtpd[7505]: sql plugin try and connect to a host
    Mar 21 15:10:18 cosmonet postfix/smtpd[7505]: sql plugin trying to open db ‘mail’ on host ’127.0.0.1′
    Mar 21 15:10:18 cosmonet saslauthd[7361]: pam_unix(smtp:auth): check pass; user unknown
    Mar 21 15:10:18 cosmonet saslauthd[7361]: pam_unix(smtp:auth): authentication failure; logname= uid=0 euid=0 tty= ruser= rhost=
    Mar 21 15:10:20 cosmonet saslauthd[7361]: DEBUG: auth_pam: pam_authenticate failed: Authentication failure
    Mar 21 15:10:20 cosmonet saslauthd[7361]: do_auth : auth failure: [user=admin@example.com] [service=smtp] [realm=example.com] [mech=pam] [reason=PAM auth error]

    I’ve spent about tree days playing with configuration files but with no luck. I’m able only to receive from outside the lan. If someone solved such a kind of behavior on ubuntu 13.10 please let me know.

  210. Hello everybody again,
    and thank you so much Adam for sharing your great work.
    Related to my previous post if someone can help me I’ve used the testsaslauthd tool with the fallowing options:

    testsaslauthd -s smtp -u user@example.com -p xxxxxxxx

    but it returns 0: NO “authentication failed”

    I’ve double checked the mysql tables data and the information stored into the configuration files, and everything seems quite right.

    Any help will be appreciated. Thanks

  211. How can I implement reject_sender_login_mismatch ?

    I created in main.cf a line:
    smtpd_sender_login_maps=mysql:/etc/postfix/maps/sender.cf
    but I don’t know to edit the file sender.cf like in you example.

    Thanks.

  212. I have the following error when you restart the “courier-pop” service:

    service courier-pop restart
    * Stopping Courier POP3 server… [ OK ]
    * Starting Courier POP3 server… Unknown option ‘-pid=’

    I appreciate your help in advance

  213. Hello,

    Nice tutorial. I have completed setup and mail server working fine. I have one question here, i can forward email from a@example.com to b@example.com. But i want a@example.com receive the email as well. Please advice how to add a BCC option. Thanks.

    Regards,

    Richard

  214. Excellent guide! I was able to get everything working. Now I’m adding a second domain, however whenever I send email from the second domain, it’s marked as spam because the headers says it’s received from my first domain. Any ideas how to fix this? Thanks a bunch!

  215. How do I access my email account? Do I need install any front-end application? Thanks

  216. Hi!

    I tried your configuration but when i see in my logs every mail is adressed to postmaster@mydomain
    here is the log

    Apr 28 12:38:52 webserver postfix/smtpd[2093]: connect from mail-vc0-f176.google.com[209.85.220.176]
    Apr 28 12:38:52 webserver postfix/cleanup[2097]: D92DF1360EFC: message-id=
    Apr 28 12:38:53 webserver postfix/smtpd[2093]: disconnect from mail-vc0-f176.google.com[209.85.220.176]
    Apr 28 12:38:53 webserver postfix/qmgr[1839]: D92DF1360EFC: from=, size=909, nrcpt=1 (queue active)
    Apr 28 12:38:53 webserver postfix/virtual[2103]: D92DF1360EFC: to=, orig_to=, relay=virtual, delay=0.18, delays=0.14/0/0/0.03, dsn=5.1.1, status=bounced (unknown user: “postmaster@mydomain”)
    Apr 28 12:38:53 webserver postfix/bounce[2106]: warning: D92DF1360EFC: undeliverable postmaster notification discarded
    Apr 28 12:38:53 webserver postfix/qmgr[1839]: D92DF1360EFC: removed

  217. Hello, i’ve followed all the tutorial, but still have problems…..i’ve changed your “admin@example.com” with my “Hypnotize@mydomain.com”, added MX record to mydomain.com, but still have this error sending an email from for example me@me.com to Hypnotize@mydomain.com:

    Your message cannot be delivered to the following recipients:

    Recipient address: Hypnotize@mydomain.com
    Reason: Remote SMTP server has rejected address
    Diagnostic code: smtp;554 5.7.1 : Sender address rejected: Access denied
    Remote system: dns;mydomain.com (TCP|17.172.220.236|53488|my.server.’s.ip|25) (semtex.localdomain ESMTP Postfix)

    Last,
    Going in mail.app and setting up new address, this not working!

    • 1) do you have your domain registered in domain-table?
      INSERT INTO domain (domain, transport, domain_enabled)
      VALUES
      (‘mydomain.com’, ‘virtual:’, 1);
      Without this Postfix wont accept any email for that domain.

      2) do you have your email address registered in users-table (OR alias-table)?
      INSERT INTO user (email, password, name)
      VALUES
      (‘Hypnotize@mydomain.com’, ENCRYPT(‘strong-mail-password’), ‘User Name’);

      From that error I assume second record does not exist and your email is rejected because email is not know by Postfix.

  218. Måns Sivertsson

    May 3, 2014 at 7:45 pm

    Hi!
    Nice tutorial!
    I’m a noob to this but how do I read all my emails I get?

  219. For those looking for quota-solution this looks promising: http://vda.sourceforge.net/

    I have *NOT* applied it yet my self, but will do so in a near future.

  220. Thank you, thank you, thank you. A million times thank you!

    I’m sure that with enough additional time, soda, isolation, etc….I could have fixed the patchwork that I was attempting to call an email server. Instead the heavens smiled upon me late last night when I stumbled across this write up. I knew instantly the best option was to re-image and follow your instructions.

    Ah the sweet, sweet taste of victory. I now have a fully functional email server up and running and I’m about to layer Horde webmail on top of it. Did I mention thank you?

  221. Hello Adam,
    Thank you for the awesome work on your howto’s! Because of your hard work I have been able to help several individuals and small businesses get up and running with a solid reliable Ubuntu mail server. I have been building mail servers for a few years with the help of this and your previous mail server guide. So a very big THANK YOU! The point being, I have a huge need to build a mail server configured with ldap, Phamm, AND Sogo, all working together nicely… I have searched google tirelessly, with no real good prospects. to even get close. No Dice! SO, the world could really use another really awesome guide. I’m hoping to convince you to create one. Perhaps I could even take up a small collection fund to commission the project if that would help.

    Regards,
    Jeff

  222. Do you have a version of this guide for Dovecot instead of Courier?

  223. Hi Adam, Thanks for the article. I have setup my mail server successfully :) but When I try to send mail form Outlook “***UNCHECKED***” is getting appended in the subject. Can you please help me on this?

    Waiting for your reply.
    Thank you

  224. hi everybody,
    i have setup my mail server
    but i cant login successfully,
    i have a error as following as:
    “ERR CHDIR VIETTEL.COM/UT/ FAILED”
    when i login :
    telnet localhost pop3
    user ut@viettel.com
    pass ut
    i created user: ut and pass: ut in database.
    CAN YOU HELP ME! :(
    I WANT TO SETTUP SUCCESSFULLY.
    PLEASE,
    UT.

  225. AMAZING!!! Saved me loads of time.

    Thank you for taking such wonderful effort to write and share.

  226. So to start off, thanks for the wonderful walk-through! This is the best I have ever seen!

    But, I appear to have done something wrong. When I attempt to connect via Thunderbird, it picks up the settings just fine,

    IMAP STARTTLS Normal password
    SMTP STARTTLS Normal password

    However, it won’t authenticate and I just keep getting “Configuration could not be verified – is the username or password wrong?” I went into mysql and verified that I have the correct password, and I’ve tried both my username and my email as the username, and I’m getting the same result.

    So I hopped over to my server and cat’d /var/log/mail.log, and I’m seeing the following errors:

    imapd: Connection, ip=[::ffff:192.168.1.68]
    imapd: LOGIN FAILED, method=PLAIN, ip=[::ffff:192.168.1.68]
    imapd: authentication error: Input/output error

    The same error is four times every time I attempt to verify settings with Thunderbird. Am I doing something wrong or using a wrong setting?

    Thanks!

  227. Which ports should we open in our server to get everything working?

  228. Actually I did ask the same question before but I could not get an answer. Sometimes I need to get some attachments which sent by mail. But I can not find those sent attachments via search commands. How can I able to find those attachments. For example, Sometime I need to make a small change on website. For Instance, changing a small picture. Instead of sending the image via ‘rsync’ I would like to be able to send via email and after that change the image via Putty.

    Thanks,
    Regards.

  229. Hi, how i can login as “MainUser” to see all mailboxes.
    Example:
    “MainUser”
    -sales@…
    -service@…
    -marketing@..

    this is possible? thanks in advanced

  230. Consider that admin manages multiple accounts. For example, admin@abc, help@abc, etc.
    In that case I need to log in all accounts . And it is waste of time. Is it possible to forwarding mails automatically

    Thanks

  231. Thank you for this guide. This was as easy as it can get. Ran into common issues of access denied.
    When I changed my main.cf
    smtpd_recipient_restrictions =permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination,per

    as per the comments above and boom everything works like a charm :D

    Thanks a ton for this guide!!!!!!

Leave a Reply

Your email address will not be published.

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Current day month ye@r *

© 2014 Pixelinx

Theme by Anders NorenUp ↑