Postfix installation-send mail sendmail command

Install postfix with the apt command to use the sendmail command to send mail.

sudo apt install -y postfix

For web system development, postfix does not have to be an incoming mail server. The main purpose of installing postfix is ​​to act as a server for delivering outbound mail and to be able to use the sendmail command.

E-mail transmission is used for sending e-mail in the inquiry form and for e-mail authentication of the account registration function.

When I execute the installation command, the GUI screen pops up and I am surprised.

(If you know how to do it with CUI, please contact "".)

Press the right side of the keyboard and Ok will illuminate. Press Enter.

Select "No configuration" with the up and down keys. Press the right key to recommend Ok, so press Enter.

The installation will start.

Confirm that postfix is ​​installed

Use the status of the systemctl command to verify that postfix is ​​installed.

sudo systemctl status postfix

I haven't started it inactive, but I have installed it.

● postfix.service --Postfix Mail Transport Agent
   Loaded: loaded (/lib/systemd/system/postfix.service; enabled; vendor preset: enabled)
   Active: inactive (dead)
Condition: start condition failed at Sat 2020-05-16 15:36:13 JST; 2 days ago

Postfix is ​​not running because there is no configuration file.

How to send an email?

How do I send an email?

From here on, I'll write about how difficult it is to send an email in the usual way.

About the function of postfix

First of all, regarding the postfix settings, various types of setting methods are posted on the Web.

postfix has three main functions: sending mail, forwarding mail, and receiving mail.

When developing a Web system, at least the only function I want is the email sending function.

If you want to find out about postfix yourself, you need to look for a procedure that is limited to the mail sending function.

About the postfix version

There are version 2 and version 3 of postfix, but there are some items that do not work or have different meanings even if the same settings are made.

DNS resolution

Next, there is an item called "myhostname" in the postfix setting item, which is specified by the name "hostname.domain name".

In this case, postfix 3 requires that the domain name be resolvable by the DNS server. With postfix 2, I feel like this wasn't required.

myhostname =
myorigin = $mydomain
relayhost = $mydomain
inet_interfaces = loopback-only
mydestination =

Block external transmission on port 25

If external sending on port 25 is blocked by VPS or cloud server, you cannot send mail with the sendmail command under normal settings.

This seems to be a measure against junk mail.

In other words, we have to assume that the environment where the outward port 25 is blocked is normal in 2020.

Authenticated SMTP server

How do you send an email if port 25 is blocked?

The easiest way is to relay postfix outbound mail to an authenticated SMTP server.

Such an email service is open to the public, and you can send emails and use up to 10,000 emails a month for free.

Therefore, the easiest and free way to get started is to use a service that provides an authenticated SMTP server.

Confirm that the sendmail command can be used

Make sure you can use sendmail.


If you're waiting for input, sendmail is installed. Let's end sendmail with Ctrl + C.

Let's send an email. Please use your own email for "Email sender" and "Email destination".

echo Hello | sendmail -f mail source mail destination

In sendmail, the standard input is the body.

-f specifies the mail sender with from. If there is no sender of the email, the email is often rejected, so I have specified it.

After that, specify the destination of the email. When testing, both the destination and the source can be the same.

Associated Information