Internal Home Email Server Question

Notice: Page may contain affiliate links for which we may earn a small commission through services like Amazon Affiliates or Skimlinks.

Leo Levosky

Member
May 17, 2017
42
1
8
I am looking to run a home email server and also host internal Bitwarden.

At the moment I am using Yahoo and Google and I intend to keep doing this but I want an internal email system for two reasons:
  1. I have various systems that can send email alerts and I don’t want to send those externally.
  2. I’m currently using POP3 as I want my email local. But this is a pain when using multiple devices.
The goal is to still use Yahoo and Gogle for mail but to fetch the email to the local server where I then use IMAP for my internal systems to read the mail. Outgoing email would still go via Yahoo and Google.

My problem is that I have no idea how to do this. Any suggestions? Can I even do this?

My fileserver is currently TrueNAS core running on an HP N54L microserver. I’m very happy with this and don’t intend to use that for email.

I also have an HP N40L microserver that used to run WHS 2011 and currently does nothing. I’d like to use this for the internal email/Bitwarden server.

So, I’m looking for suggestions on which operating system to use and how to achieve the above.

The N40L has 4GB memory and 5 2TB disks.

Any advice/suggestions?
 

BoredSysadmin

Not affiliated with Maxell
Mar 2, 2019
1,053
437
83
To run an email server at home you'd have to use SMPT (TCP/25) to send outgoing email, and this becomes a problem since most home ISPs will block outgoing port 25 to prevent spam.
 

Leo Levosky

Member
May 17, 2017
42
1
8
To run an email server at home you'd have to use SMPT (TCP/25) to send outgoing email, and this becomes a problem since most home ISPs will block outgoing port 25 to prevent spam.
That was the whole point of my question. I don't want to use the SMTP part. I just want to fetch email and read it whilst leaving SMTP to my email client and use Yahoo/Google for SMTP as I do now. My question is whether or not I can do that?
 

DavidWJohnston

Active Member
Sep 30, 2020
242
191
43
I think this would be a challenge. Why do you want your email to be local? Maybe there is a simpler alternative to reach your end goal. Anyway, IIUC, you could:

Use a cron script to download new gmail and ymail messages via POP/IMAP, then transfer them to mailbox(es) on a local email server. Then you could use an IMAP client like MS Outlook on your devices to connect to your in-house server to read the messages.

Your alerting mailbox would just be another local mailbox. All equipment sending the alerts would need to use your local SMTP server.

For sending, you could configure Outlook to send mail from your gmail and ymail accounts using SMTP, instead of using the gmail and ymail apps.

The problems I can think of are:
  • Moving messages into folders locally wouldn't be synced back to gmail/ymail
  • If you delete a message, it will not be deleted on gmail/ymail.
  • I don't know if PUSH email would work, it might be necessary to poll for new messages
  • Drafts wouldn't sync to gmail/ymail, and Sent folder might behave strangely
  • Probably a ton more I haven't thought of
With that being said, with some clever scripting, triggers, and rules I bet all of those problems could be solved. But it would be difficult. Compared to that Bitwarden will be a walk in the park.

Maybe someone else can think of a better way I'm not seeing?
 

Leo Levosky

Member
May 17, 2017
42
1
8
Thanks for your reply. I'm not sure I can get my brain around what you are saying but to clarify I don't want anything left on Gmail or Yahoo. At the moment I use POP3 to download and delete everything online as soon as it is downloaded. That works great for a single PC but I can't see any way of getting that to work on multiple devices, especially things like iPad's as they don't have the space.

All I'm trying to acheive is to download everything to a server that all my devices can access so that I can work in the same way but using IMAP on the clients. Unlike most people I don't use a mobile phone and I have no interest in accessing email externally of syncing it.

I understood there was a FETCH command or utility that I can use to download but I'm totally out of my depth on it. I don't even no what operating system to use as the basis or where to start looking.

If I understand it correctly most people leave email on Gmail/Yahoo but I really don't want to do that and I don't want to send email from systems I use internally to the Internet as I have no need to that if I can get this to work.

Does that make sense?
 

itronin

Well-Known Member
Nov 24, 2018
1,238
797
113
Denver, Colorado
...
I understood there was a FETCH command or utility that I can use to download but I'm totally out of my depth on it. I don't even no what operating system to use as the basis or where to start looking.
...
Does that make sense?
Your description makes sense however your "out of my depth" comment really implies a lot of learning (time, custom scripting etc.) is likely to be required to make this work. If you are asking does such a package of tools exist and are they plug and play compatible to make this relatively easy then AFAIK the answer is nope.

Bitwarden local server can run on windows or linux.

your platform:

The N40L is not likely to have enough oomph memory wise to really handle a full blown modern windows deployment plus what you want to do - so you are probably talking linux or *bsd at this time.
 

Stephan

Well-Known Member
Apr 21, 2017
923
700
93
Germany
Postfix for the SMTP part, Dovecot for the IMAP part. You can use fetchmail with Yahoo, if you have set up the password correctly:
Bash:
#!/bin/bash

i=1
while [ $i -le 20 ]; do
    cat <<EOF | fetchmail -f-
set syslog
set postmaster "you@yourdomain.local"
set bouncemail
set no spambounce

poll imap.mail.yahoo.com proto imap auth password timeout 120

user youruser@yahoo.com pass guessme
     smtp 127.0.0.1 smtpname you@yourdomain.local
     ssl sslproto TLS1.2+ no sslcertck
     folder Inbox,Sent,Trash,Archive,Bulk
     fetchall no rewrite
EOF
    RC=$?
    if [ $RC -eq 1 ]; then
        break
    fi
    i=$(($i+1))
    sleep 5
done
There are a few aspects. This assumes you run the script on the same box that also has Postfix. IMAP folder names of Yahoo are custom, like "Bulk". Hard to find information. Here I just pull everything from the account and send it to me via Postfix. I also try multiple times, because Yahoo basically sucks the big one. Of course this would be all polled, so you need some kind of systemd service+timer or a cron job.

Postfix will deliver it to my mailbox and then I have Dovecot for IMAP and either mutt on command line or Roundcube in browser where I edit email. Not using any GUI fat client any more.

If you want to sent outwards, easiest option is possibly to use a smart-relay with authentication (SMTP auth). Might not relay everything, just your address though. Personally I NAT outgoing port 25 SMTP over a VPN to a box at a hoster using Linux policy routing, so incoming I get everything directly and outgoing the recipient sees the clean IP from the hoster. Trying to send mail on SMTP from home user dialup pools will land you in spam or get outright rejected basically everywhere.

If you don't have a static IP like me you need to couple this with some sort of dynamic DNS. I went as far and when the home machine is offline, the box at the hoster will realize this and point all DNS entries to itself to prevent mail or clients going to a no longer valid address.

I also run rspamd in/out, with clamav and extended signatures and olefy macro-filtering and extension blacklists and a whole lot of ASNs black- and greylisted. Could have used Mailcow but I like to build stuff by hand on Arch so if something breaks, I know how to fix it.

You will learn alot, but I recommend to build a mail system one part at a time.
 

Leo Levosky

Member
May 17, 2017
42
1
8
Your description makes sense however your "out of my depth" comment really implies a lot of learning (time, custom scripting etc.) is likely to be required to make this work. If you are asking does such a package of tools exist and are they plug and play compatible to make this relatively easy then AFAIK the answer is nope.

Bitwarden local server can run on windows or linux.

your platform:

The N40L is not likely to have enough oomph memory wise to really handle a full blown modern windows deployment plus what you want to do - so you are probably talking linux or *bsd at this time.
To clarify my out of depth comment, I'm out of my depth in terms of what is available now and what is possible now. I used to be Unix sysadmin but it was long time ago. My solution will defintely not be Windows based. I got burnt by Microsoft abandoning WHS and I'm never going back to that. Most of what I do now is using Linux Mint and I only use Windows and Mac for software that only runs on those.

When I posted I was wondering if something like a Synology box would work as I thought they had a mail server on that. I've even thought of buying one just to play as I couldn't find the info online. Probably due to me being useless at searching as I give up after a few pages of results.

I configured Mail on Unix many years ago so the technology doesn't scare me but I haven't done it since and I assume things have moved on.
 
  • Like
Reactions: itronin

DavidWJohnston

Active Member
Sep 30, 2020
242
191
43
Yeah if you want to scrape your mail from gmail/ymail and have the only copy you care about be local, that simplifies things, no need to sync anything back. It'll still be a custom-scripted solution though. Unix/Linux sendmail/postfix, etc has probably changed less than you might think over the years.

Here is a tutorial that goes through the generic basic components of a Linux email server:


Then you could use something like Stephan's script to pull your email from gmail/ymail using IMAP.

To get PUSH working, if it's even possible, for gmail take a look at this:


For Ymail, I couldn't find anything specific, but take a look at this: