Temporary MDaemon, Please Postfix!

Temporary MDaemon, Please Postfix!

The following article will show you how to migrate from MDaemon to postfix.

How the mail machine works:

mailserver.hostingcompany.com is receiving mail for the agency abc.com
Use mailserver.hostingcompany.com to send mail to customers
MDaemon is running to receive and send mail
The agency is using a modem to send and receive mail.

Software used: postfix, fetchmail and wvdial in VNLinux Secure (or in other Linux versions).

Suppose the agency has The domain is abc.com and The internal network is 192.168.1.0/24 . Below is what to do once you've got postfix, fetchmail, and wvdial installed on your computer.

1. Add users to receive mail on the system:

If you use VNLinux Secure You can add users by logging in to the webtool, selecting & quot; System Administration & quot; to add users. If you use other Linux distributions, type & quot; useradd -m -s / bin / false id_user & quot; and & quot; passwd id_user_name & quot; to assign a password.

-s / bin / false This means that the shell uses / bin / false, meaning that the user will not be able to log in, but still be able to receive and send mail.

This means creating user directories in / home / id_user_name if not already available.

2. Set hostname for machine is abc.com

3. Add to /etc/postfix/main.cf the following lines

mynetworks = 192.168.1.0/24

disable_dns_lookups = yes

relayhost = mailserver.hostingcompany.com

Create a script to download and send mail

Pollmail is a script that will receive and send mail. This script is used in case you are using wvdial to connect to the network by modem every hour to send and receive mail. In this script, you will need to change mailserver.hostingcompany.com This is the address of the mail server you are using and change abc.com into your domain name. Save this script as pollmail, type & quot; chmod 755 pollmail & quot; and put this script in / usr / local / bin Note: If you do not use wvdial to connect to the network then need to revise the line near the end of the name of the program you are using (instead of wvdial). Otherwise your connection will not disconnect itself after sending and receiving mail.

#! / bin / bash
# Poll for mail
# May be run either by cron or at will by the superuser.
/ Etc / sbin: / usr / sbin: / usr / local / bin
# See if we already have PPP running
if netstat -nr | grep ppp0 & gt; / dev / null
then
echo PPP đã chạy
ppp_running = TRUE
else
# not, start it up ...
if [-f /var/run/ppp0.pid] & amp; ps -p `cat / var / run / ppp0.pid`
then
echo wvdial is running
ping -c 1 mailserver.hostingcompany.com
ppp_running = TRUE
else
ppp_running = FALSE
echo Not connecting to the net right now
sleep 2
waitpd = 0
until netstat -nr | grep ppp0 & gt; / dev / null
if ps -axu | grep -v grep | grep -E 'pppd' & gt; / dev / null
then
sleep 5
waitpd = `expr $ waitpd + 5`
if [$ waitpd -gt 120]
then
echo Timed out
exit 2
else
echo
exit 1
done
sleep 5
# Collect any mail that is waiting for us
echo & quot; Downloading mail for abc.com & quot;
fetchmail -f /root/.fetchmailrc
case $? in 0): ;; # no problem
1) echo No mail to collect ;;
2) echo Could not open socket ;;
3) echo User authentication failed ;;
4) echo Fatal protocol error ;;
5) echo syntax lỗi trong fetchmail command ;;
6) echo Bad permissions for run file control;
7) echo Server error reported ;;
8) echo Exclusion error ;;
9) echo SMTP failure ;;
10) echo Undefined error (bug in fetchmail) ;;
*) Echo Totally gặp lỗi trong fetchmail ;;
esac
echo & quot; Downloading mail for abc.com & quot;
fetchmail
case $? in 0): ;; # no problem
1) echo No mail to collect ;;
2) echo Could not open socket ;;
3) echo User authentication failed ;;
4) echo Fatal protocol error ;;
5) echo syntax lỗi trong fetchmail command ;;
6) echo Bad permissions for run file control;
7) echo Server error reported ;;
8) echo Exclusion error ;;
9) echo SMTP failure ;;
10) echo Undefined error (bug in fetchmail) ;;
*) Echo Totally gặp lỗi trong fetchmail ;;
esac
# Send anything we have for the outside world
sendmail -q
sleep 900
# If we started PPP, stop it again
if [& quot; $ ppp_running & quot; = TRUE]
then
/ bin / killall -v wvdial

5. Create a cron job to automatically connect to the network every hour and make the receipt and send mail after 3 minutes connected to the network

As root, type crontab -e Then remove these lines:

00.30 1 AzSoft_watermark_big.png cong-listening? P = 1 des.txt en_metadesc.txt en_name.txt getpageinfo.sh getpagelink.sh imglink.txt imglist.txt img.AzSoft.com label: Some Text link_original.txt link.txt logo.txt tmp02.html tmp03.html tmp2.html tmpdes3.txt tmpdesc3.txt tmpdesc4.txt tmpdesc5.txt tmpdesc6.txt tmpdesc7.txt tmpdesc.txt tmp.html tmpresult.txt tmptrans.txt transresult.txt wm.AzSoft.com www.mailenable www.microsoft.com www.securityfocus.com 1 AzSoft_watermark_big.png cong-nghe? p = 1 des.txt en_metadesc.txt en_name.txt getpageinfo.sh getpagelink.sh imglink.txt imglist.txt img.AzSoft .net -2016-200.jpg title_en .txt tmp02.html tmp03.html tmp2.html tmpdesc2.txt tmpdesc3.txt tmpdesc4.txt tmpdesc5.txt tmpdesc6.txt tmpdesc7.txt tmpdesc.txt tmp.html tmpresult.txt tmptrans.txt transresult.txt wm.AzSoft.com www .mailenable.com www.microsoft.com www.securityfocus.com 1 AzSoft_watermark_big.png AzSoft_watermark_small.png cong-nghe? p = 1 des.txt en_metadesc.txt en_name.txt getpageinfo.sh getpagelink.sh imglink.txt imglist.txt img .AzSoft.com label: Some Text link_original.txt link.txt log.txt meta_desc.txt name.txt news t-142619 testimg2-0.jpg testimg2.jpg testimg2.jpg testimg3.jpg testimg.jpg thumb tim-hieu -excel-2016-200.jpg tmp03.html tmp02.html tmpdesign.txt tmpdesktop.txt transresult.txt www.microsoft.com www.securityfocus.com elink.sh imglink.txt imglist.txt img.AzSoft.com label: Some Text link_original.txt link.txt log.txt meta_desc.txt name.txt news t-142619 testimg2-0.jpg testimg2-1.jpg testimg2.jpg testimg3.jpg testimg.jpg thumb timmy-tieu-tmp txt tmp.html tmpresult.txt tmptrans.txt transresult.txt wm.AzSoft.com www.mailenable.com www.microsoft.com www.securityfocus.com / usr / bin / wvdial
03,33 1 AzSoft_watermark_small.png cong-listening? P = 1 des.txt en_metadesc.txt en_name.txt getpageinfo.sh getpagelink.sh imglink.txt imglist.txt img.AzSoft.com label: Some Text link_original.txt link.txt logo.txt tmp02.html tmp03.html tmp2.html tmpdes3.txt tmpdesc3.txt tmpdesc4.txt tmpdesc5.txt tmpdesc6.txt tmpdesc7.txt tmpdesc.txt tmp.html tmpresult.txt tmptrans.txt transresult.txt wm.AzSoft.com www.mailenable www.microsoft.com www.securityfocus.com 1 AzSoft_watermark_big.png cong-nghe? p = 1 des.txt en_metadesc.txt en_name.txt getpageinfo.sh getpagelink.sh imglink.txt imglist.txt img.AzSoft .net -2016-200.jpg title_en .txt tmp02.html tmp03.html tmp2.html tmpdesc2.txt tmpdesc3.txt tmpdesc4.txt tmpdesc5.txt tmpdesc6.txt tmpdesc7.txt tmpdesc.txt tmp.html tmpresult.txt tmptrans.txt transresult.txt wm.AzSoft.com www .mailenable.com www.microsoft.com www.securityfocus.com 1 AzSoft_watermark_big.png AzSoft_watermark_small.png cong-nghe? p = 1 des.txt en_metadesc.txt en_name.txt getpageinfo.sh getpagelink.sh imglink.txt imglist.txt img .AzSoft.com label: Some Text link_original.txt link.txt log.txt meta_desc.txt name.txt news t-142619 testimg2-0.jpg testimg2.jpg testimg2.jpg testimg3.jpg testimg.jpg thumb tim-hieu -excel-2016-200.jpg tmp03.html tmp02.html tmpdesign.txt tmpdesktop.txt transresult.txt www.microsoft.com www.securityfocus.com elink.sh imglink.txt imglist.txt img.AzSoft.com label: Some Text link_original.txt link.txt log.txt meta_desc.txt name.txt news t-142619 testimg2-0.jpg testimg2-1.jpg testimg2.jpg testimg3.jpg testimg.jpg thumb timmy-tieu-tmp txt tmp.html tmpresult.txt tmptrans.txt transresult.txt wm.AzSoft.com www.mailenable.com www.microsoft.com www.securityfocus.com / usr / local / bin / pollmail

6. Use fetchmail to get mail from mailserver.hostingcompany.com . The pollmail script above will do this. However, you need to declare the contents of ~ / .fetchmailrc as shown below.

đặt no bouncemail
set logfile & quot; / var / log / fetchmail & quot;
đặt postmaster your_id@abc.com
set daemon 0
poll mailserver.hostingcompany.com with protocol pop3, với tùy chọn
localdomains abc.com
không có dns
envelope Envelope-to
user & quot; id_to_login_pop & quot; there with password & quot; password & quot; is 1 AzSoft_watermark_small.png cong-listening? p = 1 des.txt en_metadesc.txt en_name.txt getpageinfo.sh getpagelink.sh imglink.txt imglist.txt img.AzSoft.com label: Some Text link_original.txt link. txt log.txt meta_desc.txt name.txt news t-142619 testimg2-0.jpg testimg2-1.jpg testimg2.jpg testimg3.jpg testimg.jpg thumb tim-hieu-excel-2016-200.jpg title_vn.txt tmp02. html tmp03.html tmp2.html tmpdesc2.txt tmpdesc3.txt tmpdesc4.txt tmpdesc5.txt tmpdesc6.txt tmpdesc7.txt tmpdesc.txt tmp.html tmpresult.txt tmptrans.txt transresult.txt wm.AzSoft.com www.mailenable.com www.microsoft.com www.securityfocus.com here
với tùy chọn rewrite mimedecode fetchall pass8bits
antispam -1

1 AzSoft_watermark_small.png cong-nghe? P = 1 en_metadesc.txt en_name.txt getpageinfo.sh getpagelink.sh imglink.txt imglist.txt img.quantrimang.com label: Some Text link_original.txt link.txt log.txt meta_desc.txt name.txt news t-142619 testimg2-0.jpg testimg2-1.jpg testimg2.jpg testimg3.jpg testimg.jpg thumb tim-hieu-excel-2016-200.jpg title_vn.txt tmp02.html tmp03.html tmp2.html tmpdesc2.txt tmpdesc3.txt tmpdesc4.txt tmpdesc5.txt tmpdesc6.txt tmpdesc7.txt tmpdesc.txt tmp.html tmpresult.txt tmptrans.txt transresult.txt wm.quantrimang.com www.mailenable.com www.microsoft.com. com www.securityfocus.com Change these values ​​to suit your account

With the fetchmail configuration above, messages downloaded automatically into the user's mailbox. If mail is rejected for any reason, it will be sent to postmaster. Here postmaster is your_id@abc.com.

During the test, you can run both machines (MDaemon and Postfix) at the same time and remember to change the .fetchmailrc above, instead of fetchall in the & quot; with options ... & quot; Then replace & quot; keep & quot ;. That is, when fetchmail starts running, the message is kept on the server for MDaemon to get back (this is just in the test). When you feel that postfix mail is working, replace & quot; keep & quot; To & quot; fetchall & quot; For fetchmail to get messages (mailserver.hostingcompany.com will not have these messages after fetchmail is running).

If you are using ADSL, revise the pollmail scripts to check that the pppd connection is available and & quot; hang up & quot; pppd (in this wvdial script was used). At the same time, there is no need to create a cron job to connect to the network every half hour, like the top five.

Please note: do not forget to create a postfix user . Otherwise all messages will be sent to the postmaster.

You can read more about Postfix basics for how to handle messages in the queue.

Postfix: Basic commands for handling messages in the queue

All incoming / outgoing messages pass through the queue and they are managed by the queue manager or more explicitly by the qmgr command / program. There are 5 types of queues on postfix. It is active, bounce, corrupt, deferred, hold. And it's all in / var / spool / postfix

Administrator or two commands postsuper and postqueue to manage messages in the queue. The outgoing message stays in the deferred queue if there is a minor problem, for example, the host can not be found because the network is not connected, or because the other host is temporarily down. Messages that are rejected by the recipient or are severely corrupted by the mail server are not properly set up, will be returned to the sender immediately, meaning that the messages will not be in the queue. Any message contained in the queue will be postfixed every 17 minutes (1000 seconds) until it has been successfully sent. You can change the time that postfix checks the message in the queue (instead of 1000 seconds) by declaring / changing the value of queue_run_delay in /etc/postfix/main.cf Postfix will continue to send messages in the queue for 5 days, then return to the sender for whatever reason the message was not sent. You can change the postfix time holding the message in the queue by changing the value of maximal_queue_lifetime To view the current value (5d), type the command line [root @ proxy kdlc] # postconf | grep maximal_queue_lifetime
maximal_queue_lifetime = 5d Normally postfix sends about 5 messages at a time. Depending on the number of messages in the queue, postfix will increment this value. Value ( default_destination_concurrency_limit Maximum is 20. You should not change this value because it probably will cause the mail machine you send the message to be blocked / delayed because the message sent too many. However, you can limit the number of messages sent out at the same time by changing them smtp_destination_concurrency_limit or use local_destination_concurrency_limit To limit the delivery of messages to users. Usually the standard value of smtp_destination_concurrency_limit is 20 (ie equal to default_destination_concurrency_limit also local_destination_concurrency_limit is 2. How do you know? Type postconf | grep smtp_destination_concurrency_limit postconf | grep local_destination_concurrency_limit you will see.
  • To see how many messages are in the queue, type: postqueue -p (this is equivalent to mailq
  • To delete a message in the queue, type: postsuper -d queue_id queue_id is the value in the first column when you use the command postqueue -p
  • To delete all messages in the queue, type: postsuper -d ALL Note: ALL must be capitalized.
  • To hold a message in the queue, type: postsuper -h queue_id If you do not want to keep, type: postsuper -H queue_id Note: H is capitalized.
  • To re-queue the message, type: postsuper -r queue_id or postsuper -r ALL You will use the re-queue in case your mail server has just been rewritten with valid values ​​and you want the messages that are in the queue (due to incorrectly configured server) to be sent. Go with valid values ​​after you've reconfigured.
  • To view the contents of the message in the queue, type: postcat -q queue_id
  • To flush the messages in the queue, type: postqueue -f Note: You should not do this, but wait for postfix to send itself back. Repeat this operation several times, which can slow down your mail machine. You can dump the message in the queue for a domain you know by typing: postqueue -s domain.com
    Note: domain.com must be in variable fast_flush_domains or relay_domains
    Example: declaration fast_flush_domains = $ relay_domains domain.com in /etc/postfix/main.cf. domain.com is just an example, you need to change a real name when using. Each time modified /etc/postfix/main.cf , you have to restart postfix with the command line /etc/init.d/postfix restart or service postfix restart

    You can track postfix activity by typing tail -f /var/log/mail.log at the console. To exit, press Ctrl-C

    In the next article, I will introduce the use of clamav to filter the message virus.

    Any questions please post on vnLinux forum. The article is prepared by larry at vnlinux dot org. The pollmail and .fetchmailrc scripts are revised based on the scripts available on the network.