0

Office365 put the received mail in the INBOX folder, but also it puts many good emails in the junk folder. How can I fetch the emails from the junk folder into a local imap account, putting them in the local junk folder?

1 Answer 1

0

I solved my problem. In Linux, beside the well known fetchmail program that fetch email from other pop3 or imap account, there is another very good program: getmail. With getmail it's possible to connect a remote imap server, fetch emails from a specific imap folder and put email in another local imap folder. For example, if I want to get emails from junk foder of outlook/office365 and put in the Junk folder of a local imap account, I have to:

install getmail: with debian distros, apt install getmail

su - LOCALUSERNAME where LOCALUSERNAME is the local imap account

mkdir .getmail then create the file .getmail/getmailrc with the following content:

[retriever]
type = SimpleIMAPSSLRetriever
server = outlook.office365.com
port = 993
username = [email protected]
password = PASSWORD
mailboxes = ("Posta Indesiderata",)
# office365 is really bad: mailbox name takes the localized name, so "Posta Indesiderata" in Italian language

[destination]
type = Maildir
path = LOCALUSERNAME/Maildir/.Junk/

[options]
message_log_syslog = true
message_log_verbose = true

# retrieve only new emails
read_all = false
# delete on server after x days
delete_after = 50
# do not add a Delivered-To: header field
delivered_to = false
# do not add a Received: header field
received = false

Then, type getmail to test what happen, and if everything goes well, add getmail to the cronjob: crontab -e and put inside the line

*/5 * * * * getmail

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .