Skip to content

Instantly share code, notes, and snippets.

@ianmartorell
Created April 11, 2022 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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 "user@example.com"
there with pass "password"
mda "msmtp -a user@example.com -- destination@example.com"
folders "INBOX", "INBOX/Folder 1", , "INBOX/Folder 2"
ssl
keep
defaults
tls on
logfile ~/.msmtp.log
account user@example.com
host mail.example.com
port 587
protocol smtp
auth on
from user@example.com
user user@example.com
tls on
tls_starttls on
account default : user@example.com
# Add a new password to your keychain for smtp://mail.example.com with username user@example.com
# Fetchmail will go through all unseen emails in the specified folders of user@example.com
# and forward them to destination@example.com. 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('user@example.com', '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