메뉴
HN
Hacker News 5일 전

직접 구축하는 메일 서버

IMP
6/10
핵심 요약

셀프 호스팅 커뮤니티에서는 이메일 서버 구축을 반대하는 경향이 있지만, 올바른 설정(IP 및 DNS 레코드)을 갖추면 개인이나 기업도 안정적으로 자체 메일 서버를 구축할 수 있습니다. 이를 통해 소수 빅테크 기업에 데이터를 의존하지 않고 주권을 지키며 탈중앙화된 인터넷 환경을 만들 수 있습니다. Docker-mailserver, Mailcow 등의 솔루션과 필수 DNS 설정 가이드를 통해 누구나 쉽게 메일 서버를 호스팅할 수 있습니다.

번역된 본문

셀프 호스팅(Self-hosting)이나 데이터 주권(data-sovereignty) 커뮤니티에서 며칠만 시간을 보내다 보면, 항상 등장하는 조언이 하나 있습니다. "다른 건 다 직접 호스팅해도 이메일 서버만큼은 절대 하지 마라!"라는 것입니다. 차단 목록(blocklist)이나 수신 문제에 관한 끔찍한 사례들이 많아 그들의 말이 어디서 비롯된 것인지 이해합니다. 하지만 오늘 저는 2026년이 된 지금, 실제로 직접 구축하는 것이 가능하며 심지어 집에서 호스팅할 수도 있다는 사실을 보여드리고자 합니다. 본래 설계상 이메일은 개방형 시스템이며, 소수의 대기업이 우리의 모든 이메일을 차지하고 결과적으로 인터넷이 탈중앙화의 성격을 잃어가는 것을 우리가 받아들여서는 안 됩니다.

저의 소규모 MSP(관리형 서비스 제공자) 회사는 매일 개인과 기업이 Gmail이나 마이크로소프트에서 클라우드 대안이나 자체 호스팅 솔루션으로 전환하도록 돕고 있습니다. 그래서 저 스스로도 제 주장을 행동으로 옮겨 구글 워크스페이스(Google Workspace)에서 완전히 벗어나야겠다고 생각했습니다.

집에서 할까, VPS를 사용할까? 자체 메일 서버를 구축하려는 소수의 셀프 호스터들조차 집에서 직접 구축하려는 도전자들과 VPS(가상 사설 서버)만을 고집하는 사람들로 나뉩니다. 일반적으로는 VPS 사용을 권장하지만, 집의 인터넷 환경이 다음 조건들을 충족한다면 100% 집에서 자신만의 메일 서버를 호스팅할 수 있습니다:

  • 고정 IPv4 주소 (차단 목록에 오르지 않았는지 확인)
  • CGNAT(대규모 사설망 주소 변환) 뒤에 있지 않을 것
  • IP의 PTR 레코드를 변경할 수 있을 것 (보통 ISP 지원을 통해 가능)
  • 일반적인 메일 서버 포트(25, 143, 465, 587, 993)를 열 수 있을 것

이 모든 조건을 충족한다면, 집에서 호스팅할 준비가 끝난 것입니다!

하지만 인터넷이 끊기면 어떻게 될까요? 모뎀이 꺼지면 들어오는 이메일을 잃게 되지 않을까요? 정전 시간이 얼마나 긴지에 따라 다르겠지만, 보통은 그렇지 않습니다! 초기 인터넷 시절에는 서버 다운이 매우 흔했기 때문에, 메일 서버가 다운되더라도 발신자는 메일 전송을 재시도하도록 이메일 시스템이 설계되어 있어 매우 견고합니다. 하루 중 인터넷이 다운되는 시간이 40% 미만이라면 정상적으로 작동할 것입니다.

어떤 메일 서버 소프트웨어를 사용해야 할까요? 이는 실제로 본인의 필요에 따라 다릅니다. 호스팅 방식이 다양한 여러 메일 서버 솔루션이 존재합니다. 좋은 출발점은 합리적인 기본값과 함께 Docker를 통해 배포할 수 있는 완벽한 메일 서버 제품군인 'docker-mailserver'입니다. 하지만 다음과 같은 다른 솔루션들도 있습니다:

  • Stalwart
  • Mailcow
  • 또는, 직접 모든 서버를 구축하는 것을 선호하는 순수주의자라면 수동으로 전체 세팅을 할 수도 있습니다.

개인적으로 저는 레거시 이슈로 오랜 기간 유지해 온 ISPConfig 서버에서 제 이메일을 운영하고 있습니다. 하지만 오늘 메일 서버를 처음부터 새로 구축해야 한다면 'docker-mailserver'를 선택할 것입니다.

도메인은 어떻게 설정해야 할까요? IP와 마찬가지로 도메인이 스팸 목록에 등록되어 있는지 확인해야 하지만, 메일 수신 문제를 겪지 않으려면 몇 가지 DNS 레코드 설정이 필요합니다. 메일 서버 소프트웨어가 이 과정을 안내해 주겠지만, 내용의 완전성을 위해 필요한 핵심 레코드들을 나열해 드립니다:

  • SPF: 발신자 정책 프레임워크(Sender Policy Framework)로, 도메인에서 이메일을 보낼 수 있는 서버를 정의합니다. 일반적으로 v=spf1 mx a ~all 정도면 충분합니다.
  • DKIM: 메일 서버가 보내는 모든 이메일의 헤더에 추가하는 암호화 서명입니다. 도메인에 특정 항목이 있어야 하며, 이름과 값은 메일 서버를 통해 제공됩니다. 일반적으로 v=DKIM1; t=s; h=sha256; p=MIGf[..]B;와 같은 형태입니다.
  • DMARC: 이 항목은 기본적으로 SPF 및 DKIM의 확장이며, 귀하의 도메인을 사칭하는 이메일 스푸핑을 방지합니다. 무엇을 입력해야 할지 모르겠다면 DMARC 생성기를 사용해 보세요.
  • MX: MX 레코드는 다른 메일 서버에게 귀하의 도메인으로 이메일을 어디로 배달해야 하는지 알려줍니다. 보통 IP를 가리키는 mail.yourdomain.com의 A 레코드를 만들고, MX 레코드에 우선순위 10을 입력한 뒤 값으로 mail.yourdomain.com을 넣습니다.

또한 앞서 언급했듯이, 메일 서버에 사용하는 IP 주소는 ISP나 VPS 제공업체만 설정할 수 있는 PTR 레코드를 가져야 합니다. 이는 서버의 IP가 도메인으로 연결되도록 해주며(보통 그 반대입니다), 메일 서버에 사용하는 호스트 이름을 가리켜야 합니다(예: mail.yourdomain.com). 일부 메일 서버는 자동 서비스 탐지를 위해 몇 가지 레코드를 추가로 권장하기도 하지만, 여기까지가 핵심 설정입니다.

원문 보기
원문 보기 (영어)
If you have spent a few days online in self-hosting or data-sovereignty communities there is one advice that always pops up: You can self-host anything but not your e-mail server! I do understand where they are coming from since there are horror stories around about blocklists and delivery problems but today I want to show you that it is in fact possible in 2026 and you might even be able to host it from home! By design email is an open system and we should not accept that a few big corporations have all our mail and the internet to become less decentralized in the process. Since my small MSP company helps people and corporations on a daily basis to switch from Gmail and Microsoft to cloud alternatives or self-hosted solutions I thought I should put my money where my mouth is and also move away from Google Workspace. At home or on a VPS? The small subset of self-hosters that are willing to self-host their mailserver is again divided between those who dare to host their mailservers at home and those, who will only use a VPS. Usually I'd suggest using a VPS but if your home internet checks these boxes, you can 100% host your own mailserver at home: Static IPv4 address (make sure it's not blacklisted ) Not behind a CGNAT Ability to change the PTR record of your IP (usually though the support of your ISP) Ability to open common mailserver Ports ( 25 , 143 , 465 , 587 , 993 ) If you checked all of these, then you are ready to host at home! But what about internet outages? If my modem goes down I'll lose incoming mails, right? Depends on how long your outage is but usually: No! EMails are very robust as in if your mail server is down, the sender will retry to deliver the mail because in the early internet, outages were plentiful. If your internet is down less than 40% on any given day, it will still work fine. What mailserver software should I use? So this depends on your needs really. There are multiple mailserver solutions out there with different ways to host it. A good starting point would be docker-mailserver which is a full mailserver suite deployable via Docker with sane defaults. But there are other solutions out there like: Stalwart Mailcow Or if you're a purist you can set up your whole server yourself Personally my mail is on my ISPConfig Server which I have maintained for years for legacy reasons. If I would set up a mail server from scratch today I'd go for docker-mailserver. What about my domain? As with your IP you should check if your domain is listed on any spam list but you also need a few DNS records so you don't run into delivery troubles. Your Mailserver software will probably guide you through all that but just for completeness you'll need these records: SPF - The Sender Policy framework defines which servers can send from your Domain. Usually something like v=spf1 mx a ~all is good enough DKIM - This is a cryptographic signature your email server adds to the mail headers of every sent mail. Your domain needs to have a specific entry but the name and value will be communicated by your mailserver. looks usually like this: v=DKIM1; t=s; h=sha256; p=MIGf[..]B; DMARC - This entry is basically an extension to SPF and DKIM and should prevent email spoofing of your domain. If you are unsure what to put in here, use a DMARC generator MX - The MX records tell other mailservers where to deliver the emails on your domain. Usually you's make an A-Record for mail.yourdomain.com which points to your IP and in the MX record you put the Priority 10 and then mail.yourdomain.com as the value Also as mentioned before the IP address you use for your mailserver should have a PTR Record which can only be set by your ISP or the VPS provider. It allows the IP of the server to resolve to a domain (usually it's the other way around) and it must show to the hostname you use for your mailserver. eg mail.yourdomain.com Some mailservers also encourage you to add a few more records for automatic service detection but these are the core settings you need to get going. After you have set up your domain and server I highly recommend to test mail delivery with https://www.mail-tester.com/ which checks if all the records are correct and your server is behaving the way it should. That tool saved me lots of times. What about spam? Here comes the fun part! Spam used to be the biggest issue with self-hosted mailservers. It was so bad that I'd say it was the biggest reason people moved away from self-hosted or even (externally) hosted webmail that usually came free when you bought a web space or domain. The open source anti spam solutions relied on IP blacklists, domainlists, external anti-spam services like spamhaus or keyword searches - which were all very ineffective which caused your inbox look like this every day: Word on the street was if you don't want spam, you have to use Gmail or any of the other big cloud providers that can detect spam mail by processing millions of their clients mails every day. But something has changed in the last 2 years that solved the spam problem for self-hosters and allowed us to host our own mailservers again without being flooded by spam on a daily basis: Using local llms to fight the spam My selfhosted antispam service of choice is rspamd . It starts out as any other antispam system by having blacklists, ip checks, dns checks and keyword lookouts but there is one plugin in particular that completely fixed my spam problem: The GPT plugin This little plugin allows you to classify an email using a large language model to determine if a mail is spam or not. Since we're self-hosters and we do this also for privacy it would not make any sense to use an external LLM API to analyze all of our private emails - this is where local models come in. My model of choice for email classification is Gemma 4 12B QAT which can run on a GPU or on CPU with as little as 7GB of RAM or VRAM and is a very capable multilingual model that fits this project perfectly. If you have never set up a local llm before I'd recommed this guide from unsloth which will work on Windows, Linux and Mac. But in a nutshell you just need to run curl -LsSf https://llama.app/install.sh | sh if you're on Linux or MacOS, or run winget install llama.cpp if you're on Windows. Once installed you can expose your LLM to the world using llama serve -hf unsloth/gemma-4-12B-it-qat-GGUF:UD-Q4_K_XL --reasoning off -fa on -c 16000 --temp 0.7 and then open a browser and go to http://localhost:8080 and you should see a chat interface Once that's working all you need to do is tell rspamd to use your local llm to judge emails. For example this is my /etc/rspamd/local.d/gpt.conf on my mailserver: allow_ham = true; allow_passthrough = true; enabled = true; type = "openai"; url = "http://192.168.1.5/v1"; model = "unsloth/gemma-4-12B-it-qat-GGUF:UD-Q4_K_XL"; api_key = "this-is-ignored-on-llama.cpp"; max_tokens = 100; temperature = 0.1; # if your llm server doesn't have a GPU, you might want to increase the timeout timeout = 30.0; # Parse LLM reply as JSON (module expects key "probability", not "spam") json = true; prompt = "You are an expert email spam classifier. Analyze the following email headers, subject, and body. Respond with a JSON object containing two keys: 'probability' (a floating point number between 0.0 and 1.0 indicating spam probability) and 'reason' (a short sentence explaining why). Output only the raw JSON object, no markdown code fences."; # Per-recipient conversation context: keeps a compact digest of recent mail # (labels, top senders, 512-char summaries) in redis and injects it into the # LLM prompt once 5+ messages are collected, so classification can use the # recipient's mail history. Local feature, redis-backed, no external calls. context { enabled = true; level = "user"; # scope digest per recipient mailbox min_messages = 5; # warm-up before injection starts message_ttl = 1209600; # 14d message digests ttl = 2592000; # 30d redis key lifetime } That's all it needs to have a G