Tác giả Chủ đề: Thiết lập Postfix làm máy chủ nhận và gởi mail SMTP trên Ubuntu 16.04 (edit..)  (Đọc 1898 lần)

0 Thành viên và 1 Khách đang xem chủ đề.

Online admin

  • Administrator
  • Trung tướng
  • *****
  • Điểm yêu thích +105/-0
  • Giới tính: Nam
  • Học, học nữa, học mãi
    • Diễn đàn Nhật Bản
  • Paypal Account: admin@diendannhatban.info
Bước 1: Cài đặt Postfix
sudo apt-get update
sudo apt install mailutils

Bước 2: Thiết lập Postfix
sudo vi /etc/postfix/main.cf

/etc/postfix/main.cf
. . .
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
. . .

Change the line that reads inet_interfaces = all to inet_interfaces = loopback-only.

/etc/postfix/main.cf
. . .
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only
. . .

/etc/postfix/main.cf
. . .
mydestination = $myhostname, example.com, localhost.com, , localhost
. . .

The recommended defaults for that scenario are given in the code block below, so modify yours to match:

/etc/postfix/main.cf
. . .
mydestination = $myhostname, localhost.$mydomain, $mydomain
. . .

sudo systemctl restart postfix

Bước 3: Kiểm tra SMTP Server
echo "This is the body of the email" | mail -s "This is the subject line" your_email_address

Bước 4: Forwarding Mail
To configure Postfix so that system-generated emails will be sent to your email address, you need to edit the /etc/aliases file.

sudo nano /etc/aliases
The full contents of the file on a default installation of Ubuntu 16.04 are as follows:

/etc/aliases
# See man 5 aliases for format
postmaster:    root

/etc/aliases
# See man 5 aliases for format
postmaster:    root
root:          your_email_address
Replace your_email_address with your personal email address. When finished, save and close the file. For the change to take effect, run the following command:

sudo newaliases
You may now test that it works by sending an email to the root account using:

echo "This is the body of the email" | mail -s "This is the subject line" root
You should receive the email at your email address. If not, check your spam folder.

Conclusion
That's all it takes to set up a send-only email server using Postfix. You may want to take some additional steps to protect your domain from spammers.

If your use case is to receive notifications from your server at a single address, emails being marked as spam is a major issue because you can whitelist them. However, if your use case is to send emails to potential site users (such as confirmation emails for a message board sign-up), you should definitely set up SPF records and DKIM so your server's emails are more likely to be seen as legitimate.

How To use an SPF Record to Prevent Spoofing & Improve E-mail Reliability

How To Install and Configure DKIM with Postfix on Debian Wheezy Though that article was written for Debian Wheezy, the same steps apply for Ubuntu 16.04.

If configured correctly, this makes it difficult to send spam with an address that appears to originate from your domain. Doing these additional configuration steps will also make it more likely for common mail providers to see emails from your server as legitimate.




Diễn đàn Nhật Bản