usually,Maybe not many people will encounter this situation,That means you want to change your email address,But you need to bring the emails in your current mailbox with you。But once it happens,You will find,Something that is almost the same age as the Internet,There is no mature export and import function。
What's more troublesome than this is,If you are a mail server administrator,You find out tragically,It doesn’t work even if you have server permissions.。The content in the mailbox is stored using special methods,It is not a simple database,Requires the use of corresponding services for access,Moving files directly is likely to cause data corruption,The gain outweighs the loss。 imapsync It comes in handy,It uses email directly IMAP protocol,Download data from old mailbox,Then sync to new mailbox,The sender of the message,recipient,time,Accessories, etc. are all available!
problem
of course,If it were that simple it would be over,Then the point of this article is gone - I have a more complex use case,My client needs to migrate their mailboxes to a new server,Use new panel,which isMigrate from Plesk to Hestia。 So the question is,There is only one domain name,How can I get from A to B but only using A?
Finally my solution was to create a temporary mailbox,Use domain name B,So I can sync emails from A to B first,Then modify the domain name configuration,Resolve domain name to new server,Then synchronize emails from B back to A。Because the domain name has been resolved to the new server at this time,In fact, the mail is synchronized to the new mail server.。Then use the same account and password for users created on the new server.,In theory, customers don’t need to make any changes,Just tolerate a short service outage and you'll be fine。
Configuration / pitfalls
There is some additional configuration that needs to be done,by default,If you open Hestia's webmail,You will see an internal error,This is due to file permissions,Use the following two commands to fix:
1 2 |
sudo chown -R hestiamail:hestiamail /etc/roundcube/ sudo find /etc/roundcube/ -type f -iname "*php" -exec chmod 640 {} \; |
Other,If your mailbox can successfully send emails but cannot receive them,Need to view Exim4 Journal: /where/log/exim4/rejectlog ,If there is an error similar to the following:
1 |
Rejected because 209.85.214.171 is in a black list at zen.spamhaus.org |
That's most likely because Exim4 uses the default spamhaus List is too aggressive。 In my test,It will directly block any gmail email,we can remove it。edit /etc/exim4/dnsbl.conf Remove zen.spamhaus.org Just save this line。Then restart Exim4 using the command systemctl restart exim4
imapsync
If you happen to use it like me macOS if,Please do not use homebrew Install imapsync。From 2021 start of year,The imapsync installed by brew has a strange memory leak problem,This problem has not been fixed yet (yes,I also encountered it)。The convenient and worry-free solution is to install the dependencies and run it directly on Ubuntu。Of course, if you find it troublesome,You can also use Docker,Here I found oneImage that supports arm64 You can use this image directly to run imapsync,Stable and efficient!
Here is an example of the command I use:
1 2 3 4 |
docker run --rm -it jauderho/imapsync:latest \ --host1 hostFrom.com --user1 your_address1 --password1 "pwd1" \ --host2 hostTo.com --user2 your_address2 --password2 "pwd2" \ --automap |
It is noteworthy that,Your password should be enclosed in double quotes,This can avoid command errors caused by some special symbol conflicts.。
Other,It is highly recommended to run this command on your new server,Because imapsync will download and upload everything - including attachments。This will be a very long operation。Ideally run on your new server,This way the data can be downloaded directly to your server,Then store it locally in the database。Especially if I need to synchronize two mailboxes on the same server later.,And the upload capacity of ordinary home broadband is very small.,What a big hole。
Spam and antivirus function switch
Configure Hestia spamassassin and clamaav 。If you are like me and use Lightsail with small memory as your server,So even if you check these two modules,They may also not be installed,At this time we need to install them manually: sudo apt install spamassassin clamav clamav-daemon
edit Hestia configuration file sudo we /usr/local/hestia/conf/hestia.conf ,Add the following two lines at the beginning of the file:
1 2 |
ANTISPAM_SYSTEM='spamassassin' ANTIVIRUS_SYSTEM='clamav-daemon' |
Enter settings in the Hestia administrator account interface→exim4 The editing interface,place the following 4 Uncomment the line:
Then execute the following commands line by line to configure clamav
1 2 3 4 5 |
gpasswd -a clamav mail > /dev/null 2>&1 gpasswd -a clamav Debian-exim > /dev/null 2>&1 cp -f /usr/local/hestia/install/deb/clamav/clamd.conf /etc/clamav/ update-rc.d clamav-daemon defaults systemctl start clamav-daemon |
There is also the following command configuration spamassassin
1 2 3 4 |
update-rc.d spamassassin defaults > /dev/null 2>&1 sed -i "s/ENABLED=0/ENABLED=1/" /etc/default/spamassassin systemctl start spamassassin systemctl enable spamassassin > /dev/null 2>&1 |
Last edited file /etc/roundcube/config.inc.php ,Add the following at the top:
1 2 3 4 5 6 7 |
// See real folder names in Roundcube, only temp. activated: // Disable localization of the default folder names listed above $config['show_real_foldernames'] = true; // default folder to store spam messages // NOTE: Use folder names with namespace prefix (INBOX. on Courier-IMAP) $config['junk_mbox'] = 'Spam'; |
Restart the server,Then you can Hestia In the mailbox configuration interface, you can see the spam and anti-virus switches.。
Original article written by LogStudio:R0uter's Blog » imapsync mailbox migration from Plesk to Hestia
Reproduced Please keep the source and description link:https://www.logcg.com/archives/3853.html