Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build a mail server in Ubuntu environment

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to build a mail server in the Ubuntu environment". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to build a mail server in the Ubuntu environment".

Install Dovecot

Start your Ubuntu system and install Dovecot:

$sudo apt-get install dovecot-imapd dovecot-pop3d

It installs available configurations and starts automatically after completion. You can use ps ax | grep dovecot to confirm:

$ps ax | grep dovecot 15988? Ss 0:00 / usr/sbin/dovecot 15990? S 0:00 dovecot/anvil 15991? S 0:00 dovecot/log

Open your Postfix configuration file / etc/postfix/main.cf and make sure you configure maildir instead of mbox for email storage. Mbox gives each user a single large file, while maildir stores each message as a file. A large number of small files are more stable and easier to manage than a large one. Add the following two lines, the second line telling Postfix that you need maildir format, and create a .mail directory under each user's home directory. You can take any name, not necessarily .Mail:

Mail_spool_directory = / var/mail home_mailbox = .Mail /

Now adjust your Dovecot configuration. First, rename the original dovecot.conf file aside, because it invokes the file stored in conf.d, making it easier to put the configuration together when you're just starting to learn:

$sudo mv / etc/dovecot/dovecot.conf / etc/dovecot/dovecot-oldconf

Now create a new / etc/dovecot/dovecot.conf:

Disable_plaintext_auth = no mail_location = maildir:~/.Mail namespace inbox {inbox = yes mailbox Drafts {special_use =\ Drafts} mailbox Sent {special_use =\ Sent} mailbox Trash {special_use =\ Trash}} passdb {driver = pam} protocols = "imap pop3" ssl = no userdb {driver = passwd}

Note that mail_location = maildir must match the home_mailbox parameter in main.cf. Save your changes and reload the Postfix and Dovecot configuration:

$sudo postfix reload $sudo dovecot reload

Quickly export configuration

Use the following command to quickly view your Postfix and Dovecot configuration:

$postconf-n $doveconf-n

Test Dovecot

Now start telnet again and send yourself a test message. The bold type shows the command you entered. Studio is the hostname of my server, so you must use your own:

$telnet studio 25 Trying 127.0.1.1... Connected to studio. Escape character is'^]'. 220 studio.router ESMTP Postfix (Ubuntu) EHLO studio 250-studio.router 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-8BITMIME 250-DSN 250 SMTPUTF8 mail from: tester@test.net 250 2.1.0 Ok rcpt to: carla@studio 250 2.1.5 Ok data 354 End data with .Date: November 25, 2016 From: tester Message-ID: first-test Subject: mail server test Hi carla, Are you reading this? Let me know if you didn't get this. . 250 2.0.0 Ok: queued as 0C261A1F0F quit 221 2.0.0 Bye Connection closed by foreign host.

Now request Dovecot to retrieve your new message and log in with your Linux username and password:

$telnet studio 110 Trying 127.0.0.1... Connected to studio. Escape character is'^]'. + OK Dovecot ready. User carla + OK pass password + OK Logged in. Stat + OK 2809 list + OK 2 messages: 1 383 2426. Retr 2 + OK 426 octets Return-Path: X-Original-To: carla@studio Delivered-To: carla@studio Received: from studio (localhost [127.0.0.1]) by studio.router (Postfix) with ESMTP id 0C261A1F0F for; Wed, 30 Nov 2016 17:18:57-0800 (PST) Date: November 25, 2016 From: tester@studio.router Message-ID: first-test Subject: mail server test Hi carla, Are you reading this? Let me know if you didn't get this. . Quit + OK Logging out. Connection closed by foreign host.

Take a moment to compare the messages entered in the * * example with the messages received in the second example. The return address and date are easy to forge, but Postfix is not fooled. Most mail clients display a minimum set of headers by default, but you need to read the full header to see the actual backtracking.

You can also check your email in your ~ / Mail/cur directory. They are plain text. I already have two test emails:

$ls .Mail / cur/ 1480540325.V806I28e0229M351743.studioRich 2Magazine S 1480555224.V806I28e000eM41463.studioRu 2JI S

Test IMAP

Our Dovecot has both POP3 and IMAP services enabled, so let's test IMAP with telnet.

$telnet studio imap2 Trying 127.0.1.1... Connected to studio. Escape character is'^]'. * OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE AUTH=PLAIN] Dovecot ready. A1 LOGIN carla password A1 OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS BINARY MOVE SPECIAL-USE] Logged in A2 LIST "" * * LIST (\ HasNoChildren) "." INBOX A2 OK List completed (0.000 + 0.000 secs). A3 EXAMINE INBOX * FLAGS (\ Answered\ Flagged\ Deleted\ Seen\ Draft) * OK [PERMANENTFLAGS ()] Read-only mailbox. * 2 EXISTS * 0 RECENT * OK [UIDVALIDITY 1480539462] UIDs valid * OK [UIDNEXT 3] Predicted next UID * OK [HIGHESTMODSEQ 1] Highest A3 OK [READ-ONLY] Examine completed (0.000 + 0.000 secs). A4 logout * BYE Logging out A4 OK Logout completed. Connection closed by foreign host

Thunderbird mail client

The screenshot in figure 1 shows the messages in the graphical mail client on another host on my LAN.

Figure 1: Thunderbird mail

At this point, you have a working IMAP and POP3 mail server, and you know how to test your server. Your users can choose the protocol to use when they set up an email client. If you only want to support one mail protocol, just leave the name of the protocol you want in your Dovecot configuration.

Thank you for your reading, the above is the content of "how to build a mail server in the Ubuntu environment". After the study of this article, I believe you have a deeper understanding of how to build a mail server in the Ubuntu environment, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report