Not sure if there’s a pre-existing solution to this, so I figured I’d just ask to save myself some trouble. I’m running out of space in my Gmail account and switching email providers isn’t something I’m interested in. I don’t want to pay for Google Drive and I already self-host a ton of other things, so I’m wondering if there is a way to basically offload the storage for the account.

It’s been like 2 decades since I set up an email server, but it’s possible to have an email client download all the messages from Gmail and remove them from the server. I would like to set up a service on my servers to do that and then act as mail server for my clients. Gmail would still be the outgoing relay and the always-on remote mailbox, but emails would eventually be stored locally where I have plenty of space.

All my clients are VPN’d together with Tailscale, so the lack of external access is not an issue. I’m sure I could slap something roughshod together with Linux packages but if there’s a good application for doing this out there already, I’d rather use it and save some time.

Any suggestions? I run all my other stuff in Kubernetes, so if there’s one with a Helm chart already I’d prefer it. Not opposed to rolling my own image if needed though.

  • Darkassassin07@lemmy.ca
    link
    fedilink
    English
    arrow-up
    13
    ·
    edit-2
    3 months ago

    Bit of a different solution:

    If Paperless-NGX is one of the things you self-host; it has options to import emails based on your specified criteria, then you could have it delete each piece of mail it imports. You can also just have it move mail to folders on the mail server, or just tag/flag mail instead of deleting it. (for you to then manually delete at your leisure)

    I use this to automatically import receipts, bills, work documents, and any other regular mail instead of dealing with it manually every week/month.

    • peaceb@lemmy.world
      link
      fedilink
      English
      arrow-up
      4
      ·
      3 months ago

      I’ve never noticed that in the docs! That’s pretty cool. I’ll have to try set it up sometime.

  • conrad82@lemmy.world
    link
    fedilink
    English
    arrow-up
    7
    ·
    3 months ago

    Not sure if it fits you, but personally I have set up a self hosted dovecot instance where i have moved old gmail emails to, using thunderbird as the client.

  • TCB13@lemmy.world
    link
    fedilink
    English
    arrow-up
    4
    ·
    3 months ago

    it’s possible to have an email client download all the messages from Gmail and remove them from the server. I would like to set up a service on my servers to do that and then act as mail server for my clients. Gmail would still be the outgoing relay and the always-on remote mailbox, but emails would eventually be stored locally where I have plenty of space.

    Do you really need this extra server? Why not just configure the account on Thunderbird and move the older / archival mail to a local folder? Or even drag and drop it out of Thunderbird to a folder and store the resulting files somewhere?

    I’m just asking this because most people won’t need regular access to very old email and just storing the files on a NAS or something makes it easier.

    • countstex@feddit.dk
      link
      fedilink
      English
      arrow-up
      2
      ·
      3 months ago

      I’m not the OP but I like how you are thinking. Might look into this idea myself.

  • bigBananas@feddit.nl
    link
    fedilink
    English
    arrow-up
    4
    ·
    3 months ago

    Basically every serious mailserver package has imapsync included. I don’t know what kind of hardware you’re running and what you expect from the server doing the copying but running webmail, search indexes, antivirus, etc will cost you ram. There are solutions aimed at keeping backups of your mail though, I can’t give you recommendations, the only thing I remember is that they don’t give you a normal webmail or imap, instead you get a web-interface aimed at searching through the backup(s)

  • schizo@forum.uncomfortable.business
    link
    fedilink
    English
    arrow-up
    4
    ·
    3 months ago

    Do they need to be the same mailbox?

    Could you have a ‘live’ and ‘archive’ split?

    If you could, then I’d use something like imapsync to make a complete mirror copy, and then delete all email older than whatever the age is that makes them outside of your usual working set, and bam, done.

    The problem you’re going to have is there’s a LOT of tools that can sync imap->imap, but they’re more migration or backup tools and won’t let you delete the email from gmail afterwards while maintaining a usable archive, which I think is a requirement to solve your issue.

    • thundermoose@lemmy.worldOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      3 months ago

      Yeah, they are ideally the same mailbox. I’d like a similar experience to Gmail, but with all the emails rehomed to my server.

  • bdabb@lemmy.world
    link
    fedilink
    English
    arrow-up
    4
    ·
    3 months ago

    I’ve setup exactly what you’ve described. Some of the stories of people suddenly losing access to their Google accounts scared me enough that I wanted a copy of all my emails locally in case the same thing happened to me.

    I setup an IMAP email server using Dovecot which I can access over my Tailnet from various client machines. I use Getmail on the server to periodically poll Gmail every few minutes for any new messages via POP access. Anything new is downloaded and dumped in the user’s inbox.

    It’s a pretty solid setup - I’ve been using it for years.

  • hendrik@palaver.p3x.de
    link
    fedilink
    English
    arrow-up
    3
    ·
    3 months ago

    I usually look at these awesome … lists. They list quite some mail servers:

    https://github.com/awesome-selfhosted/awesome-selfhosted?tab=readme-ov-file#communication—email—complete-solutions

    I think you first need a mailserver, then you’d use imapsync (for example) to move the mailbox initially, and then periodically fetch the mails from gmail.

    For outgoing mail you can either configure your mailserver to relay mail via your gmail account. Or configure your mail program to send mail directly via gmail.

  • stegosaur5491@lemm.ee
    link
    fedilink
    English
    arrow-up
    3
    ·
    3 months ago

    I use the same setup as @conrad82@lemmy.world described. So selfhosted mail server and manual transfer via thunderbird.

    If I get you right, you already have a similar setup. Then you are asking only for a automatic solution to transfer the emails from one account to another. Right?

    Haven’t tried it, but what about docker-mbsync? Or maybe you can put together an image like this on your own (cron job & simple email sync/transfer client, maybe mbsync or imapsync)?

    Then you could sync all folders to your local account. In your email client you can use the imap settings from local account and smtp settings from gmail. You could even host your client too.

    • thundermoose@lemmy.worldOP
      link
      fedilink
      English
      arrow-up
      2
      ·
      3 months ago

      It’s really more of a proxy setup that I’m looking for. With thunderbird, you can get what I’m describing for a single client. But if I want to have access to those emails from several clients, there needs to be a shared server to access.

      docker-mbsync might be a component I could use, but doesn’t sound like there’s a ready-made solution for this today.

      • conrad82@lemmy.world
        link
        fedilink
        English
        arrow-up
        2
        ·
        3 months ago

        dovecot provides a proper shared imap server. But not all email clients allow moving emails between accounts (gmail and local email server), but Thunderbird does.

        I can access the emails from any client

  • ChojinDSL
    link
    fedilink
    English
    arrow-up
    3
    ·
    3 months ago

    You could setup imapsync and sync your Gmail to a self hosted IMAP server and just never delete your mails.

  • tvcvt@lemmy.ml
    link
    fedilink
    English
    arrow-up
    2
    ·
    3 months ago

    The thing that immediately came to mind was mailpiler.org. It’s been on my list to stand up for a while, but I’ve never got around to it.

  • Fedditor385@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    3 months ago

    I think there is a possibility to have a local client using Gmail, with a rule set to delete mails on Gmail as soon as they are synced locally. So in this case Gmail would be nothing more than a relay/proxy, while your mails would actually be offline.

    • seaQueue@lemmy.world
      link
      fedilink
      English
      arrow-up
      1
      ·
      3 months ago

      You can access Gmail over IMAP and pull down messages locally. If you do this; Back. Up. Your. Mbox.

      Also, fun fact, you can move messages from a local mbox to Gmail while preserving read status and original dates if you want to add old email to Gmail for some reason.