Skip to content

Instantly share code, notes, and snippets.

@ianmartorell
Created April 11, 2022 15:50
Show Gist options
  • Save ianmartorell/47849bbda739a43d387ac10b23be2ab2 to your computer and use it in GitHub Desktop.
Save ianmartorell/47849bbda739a43d387ac10b23be2ab2 to your computer and use it in GitHub Desktop.
Forward all emails in mailbox with folders
# ~/.fetchmailrc
poll mail.privateemail.com
with proto IMAP
uidl
user "[email protected]"
there with pass "password"
mda "msmtp -a [email protected] -- [email protected]"
folders "INBOX", "INBOX/Folder 1", , "INBOX/Folder 2"
ssl
keep
defaults
tls on
logfile ~/.msmtp.log
account [email protected]
host mail.example.com
port 587
protocol smtp
auth on
from [email protected]
user [email protected]
tls on
tls_starttls on
account default : [email protected]
# Add a new password to your keychain for smtp://mail.example.com with username [email protected]
# Fetchmail will go through all unseen emails in the specified folders of [email protected]
# and forward them to [email protected]. You can use the python script to mark all
# emails in a folder as unread. Fetchmail will mark them as read as they are forwarded.
fetchmail
from imap_tools import MailBox, MailMessageFlags, A
with MailBox('mail.example.com').login('[email protected]', 'password', 'INBOX/Folder name') as mailbox:
mailbox.flag(mailbox.uids(A(seen=True)), MailMessageFlags.SEEN, False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment