cygwin setting #4 – install SMTP, POP and IMAP email server
Published by Nineye under learning os on February 19, 2009원문 : http://pigtail.net/LRP/exim/exim-cygwin.html
How to install an enterprise-class SMTP server (a GNU (GPL) free software from Cambridge University called exim ) on a Windows 2000 or Windows XP machine as an experiment.
For real world use, you are better off with exim on a Linux platform, or Exchange Server for serious business use.
If you need a custom business grade email system, intermedia.net has what you are looking for.
Please don’t send any questions to the cygwin mailing list to ask questions about this page as it may provoke them. The information here is provided “as is, in good faith” with no guarantee it will work. If it doesn’t work, then it doesn’t work. Don’t send any questions to the cygwin mailing list to ask why and provoke them. Read this Disclaimer.
Constructive comments are of course welcome, in the original spirit of the Internet, sharing experience and knowledge regarding bug fixes and improvements to benefit other users of the Internet community.

(1) Login to Windows 2000/XP as Administrator; or login as a user with administrator privilege,
(1a) Make sure the Administrator or user has a login password already created AND the user name contain no spaces.
(2a) Create a folder called c:\cygwin
(2b) Download setup.exe from http://www.cygwin.com/ and save setup.exe to c:\cygwin
(2c) Click Start…Run…and type c:\cygwin\setup.exe
When it asks “Select Root Installation Directory“, the root directory should be c:\cygwin
The “Local Package Directory” should also be c:\cygwin
Select a download site close to your.
When a selection screen comes up, click the little View button for “Full” view,
find the line “cygrunsrv”, click on the word “skip” so that an ’x’ mark appears in Column B, see this illustration,
(thanks to Ross Hemingway of Kingston, Ontario, Canada)
find the line “exim”, click on the word “skip” so that an ’x’ mark appears in Column B, see this illustration.
Click ’next’ to start the installation.
Size of the basic cygwin system is about 70 Meg when installed, this may take a while. Take a coffee break
(3) Right click My Computer icon, Properties, Advanced, Environment Variables. See this illustration (red dots).
In the Systems Variable section (lower section), click the “New” button to add a new entry to system variables:
variable name is CYGWIN
variable value is ntsec
(4) Right click My Computer icon, Properties, Advanced, Environment Variables. See this illustration (green dots).
Select the Path variable and click the “Edit” button:
append ;c:\cygwin\bin to the end of the existing variable string.
(5) Open a cygwin window (by double clicking the cygwin shell execution icon), a black screen pops up, type
| exim-config |
when asked “local postmaster”, type the currently logon user name.
when asked “fully qualified primary host name”,
- if you don’t know your fully qualified host name, use the suggested name by answering yes
- if you do know your fully qualified host name, answer no then type in your machine’s FQDN, e.g. mail.mydomain.com
when asked about some “sendmail” gooblygook, answer yes
when asked “do you want to install exim daemon as a service”, answer yes
when asked “enter period of the queue runner”, answer 15
when asked “value of CYGWIN”, just hit Enter
when asked “start the exim daemon as a service now”, answer yes
(6) Check to make sure exim (SMTP server) is running, type
| netstat -an | grep 25 |
You should see a response like “TCP 0.0.0.0:25 LISTENING”
To stop the exim email server, type
| net stop exim |
To start the exim email server again, type
| net start exim |
(7) You can make your exim on Windows to be your outbound SMTP server for all your internal networked PC.
(7a) If you have Windows XP, invoke Control Panel.. Security Centre.. Windows Firewall.. Exceptions Tab..
Add port… Name is exim, Port Number is 25
(7b) Install a free editor called notepad++ (use Google search keyword notepad++)
(7c) Invoke Notepad++, click File…Open… c:\cygwin\etc\exim.conf
Find this line: hostlist relay_from_hosts = 127.0.0.1
change it to
| hostlist relay_from_hosts = 127.0.0.1 : 192.168.1.0/24 |
The above tweak tells exim to accept emails (for sending) from any PC with an IP address of 192.168.1.xx
Geeks call this “relaying mail for the subnet 192.168.1.0/24″ to intimidate you.
Your local network subnet number may be different than above, for example,
D-Link routers use default subnet 192.168.0.xx, Linksys routers use default subnet 192.168.1.xx, SMC routers use default subnet 192.168.2.xx
If you use a D-Link routers, replace above with 192.168.0.0/24 for SMC routers, replace above with 192.168.2.0/24
(7d) Find this line: host_lookup = !127.0.0.1/8:*
and change it to (geeks call it “comment it out”)
| # host_lookup = !127.0.0.1/8:* |
(7e) Find this line: rfc1413_query_timeout = 30s
change it to
| rfc1413_query_timeout = 1s |
(7f) Find this line: require verify = senders
change it to (geeks call it comment it out)
| # require verify = senders |
(8) Inbound SMTP server.
If you have registered a domain name and setup an MX record pointing to your machine,
and you want exim to accept inbound mails sent to, e.g., me@mydomain.com
add your domain name to the line “domainlist local_domains=@“
For example, if your domain is ibm.com, find the line that says “domainlist local_domains=@, change it to
| domainlist local_domains=@:ibm.com |
(9) After you modify and save c:\cygwin\etc\exim.conf, restart the exim email server by typing:
| net stop exim net start exim |
Anti-spam measures at all ISP make their email servers reject emails sent from
“dynamic IP” and “residential IP” addresses, despite the email servers are non-spamming.
This has very bad implications for SOHO who want to free themselves from the extra costs,
hours of mail delays at the ISP smtp server, and other unreasonable restrictions imposed by the ISP.
There is no easy work around.
The soft work around is use the ISP’s email server for outgoing mails (SMTP server),
and still use an in-house email server (such as exim) for receiving in-coming mails.
(provided that your paranoia-dementia ISP do not block TCP port 25, it is senseless to block TCP port 25 because
the incoming and outgoing load will simply be shifted to their already overloaded smtp servers)
Edit the file c:\cygwin\etc\exim.conf so that exim will not send mail directly to
the outside world, instead, it sends all outgoing mails to your ISP’s overloaded SMTP server,
then let your ISP’s overloaded SMTP server sends the mail out several minutes (or hours) later.
older exim version 3: ( exim -bV will tell you which version you are using)
Use EditpadLite to File.. Open c:\cygwin\etc\exim.conf , find the section that says
“ROUTERS CONFIGURATION”
just below that line, add 4 lines:
| my_friendly_isp: driver = domainlist transport = remote_smtp route_list = * your.isp.mail.server bydns_a |
substitute your.isp.mail.server with the actual SMTP host name or the IP address of your ISP’s SMTP mail server.
(current) exim version 4: ( exim -bV will confirm which version you have installed)
Use EditpadLite to File…Open c:\cygwin\etc\exim.conf , find the section that says
ROUTERS CONFIGURATION
just below the “begin routers” line, add 5 lines:
| smart_route: driver = manualroute domains = !+local_domains transport = remote_smtp route_list = * your.isp.smtp.server |
substitute your.isp.smtp.server with the actual host name or the IP address of your ISP’s SMTP mail server. You can ask them or find it from their web site.
After you modify and save exim.conf , restart exim
| net stop exim net start exim |
How to install a POP3 and IMAP server on a Windows 2000 or Windows XP
for hosting emails for Windows users for one Internet domain.
To receive in-coming emails, you need to have a static or nearly static IP address that is accessible from the outside,
and a properly set up DNS, see this page.
Click Start…Run…and type c:\cygwin\setup.exe
When a selection screen comes up, click the little View button for “Full” view,
find the line “inetutils“, click on the word “skip” so that an ’x’ mark appears in Column B,
find the line ”uw-imap-imapd“, click on the word “skip” so that an ’x’ mark appears in Column B,
Click ’next’ to start installing inetutils and University of Washington IMAP/POP3 servers.
Invoke Notepad++, File…Open…. c:\cygwin\etc\inetd.conf
add two lines
| pop3 stream tcp nowait root /usr/sbin/uw-ipop3d imap stream tcp nowait root /usr/sbin/uw-imapd |
Open a cygwin window (by double clicking the cygwin shell execution icon), a black screen pops up
| /usr/sbin/inetd –install-as-service net start inetd rm -f /var/mail mkdir /var/mail cd /var/spool ln -s ../mail /var/spool/mail (if this does not work; ln -s /var/spool/mail /varl/mail/ ) |
Thanks to Chris Klomp for the above.
If you use Windows XP, invoke Control Panel.. Security Centre.. Windows Firewall.. Exceptions Tab..
Add port .. Name is pop3, Port Number is 110
Add port… Name is imap, Port Number is 143
Open a cygwin window (by double clicking the cygwin shell execution icon), a black screen pops up
netstat -an | grep 110 to verify that pop3 server is listening, you should see a response like “TCP 0.0.0.0:110 LISTENING”
netstat -an | grep 143 to verify that imap server is listening, you should see a response like “TCP 0.0.0.0:143 LISTENING”
If you have an external router/firewall (e.g. D-Link or Linksys), port forward TCP 110 and TCP 143 to this internal machine as well,
so that your users from outside can talk to your pop3 and imap server.
Multiple Windows users
Create other Windows users (do not use spaces in user name)
Use the Control Panel…User Accounts.
After you created (or removed) Windows users
pop a cygwin shell execution icon cygwin windows to harmonize the Windows user information with cygwin
| mkpasswd –local > /etc/passwd mkgroup –local > /etc/group chmod 1777 /var/mail |
The above chmod tweak is a contribution by Kevin Hilton of Chicago, IL, USA.
The chmod tweak is needed when you have more than one user on the same computer.
These tweaks likely are not needed with recent versions of cygwin exim
chown SYSTEM:root /etc/exim.conf
chown -R SYSTEM:Users /var/log/exim
chown -R SYSTEM:Users /var/log/exim/*
Install a robust, high quality email client Mozilla Thunderbird Email,
configure the “Outgoing SMTP Server” IP address to be 127.0.0.1
(geek’s terminology 127.0.0.1 means the machine itself, some geeks call it a “localhost“)
configure Thunderbird to use the “Incoming POP or IMAP Server” IP address to be 127.0.0.1
(geek’s terminology 127.0.0.1 means the machine itself, some geeks call it a “localhost“)
For the other client machines on your internal local network, do the same except
replace 127.0.0.1 with the actual IP address of your SMTP/POP3/IMAP server (e.g. 192.168.1.3 )
Maintenance
Clean up (geeks call purge) the exim log file once a week (or once a month)
Manual method:
pop up a Cygwin windows, and type
| rm /var/log/exim_main.log |
Automatic method:
Windows Method
(1) create a batch file (e.g. c:\ cleanup-exim.bat ) with one line:
| del c:\cygwin\var\log\exim\exim_main.log |
(2) invoke Control Panel, Performance and Maintenance, Scheduled Task, add a Scheduled Task as Administrator or user with admin privilege
to run c:\cleanup-exim.bat once a week.
Cygwin method (not fully tested)
(1) run c:\cygwin\setup.exe to install cron and mc (Midnight Commander)
(2) pop a Cygwin windows
(3) cd /etc/cron.d
(4) touch purge-exim-log
(5) mc, select purge-exim-log, then hit F4 to edit the file
(6) The content of the purge-exim-log file may look something like this (in cron terminology: every Saturday at 2:00 am)
00 02 * * 6 SYSTEM:root /usr/bin/rm /var/log/exim/exim*.log
A book on exim from O’REILLY books
exim man page Unix style