<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.zhouba.cz/index.php?action=history&amp;feed=atom&amp;title=ZhoubaWiki%3AHowToSetupSmtpServer</id>
	<title>ZhoubaWiki:HowToSetupSmtpServer - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.zhouba.cz/index.php?action=history&amp;feed=atom&amp;title=ZhoubaWiki%3AHowToSetupSmtpServer"/>
	<link rel="alternate" type="text/html" href="https://wiki.zhouba.cz/index.php?title=ZhoubaWiki:HowToSetupSmtpServer&amp;action=history"/>
	<updated>2026-04-08T22:55:55Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.2</generator>
	<entry>
		<id>https://wiki.zhouba.cz/index.php?title=ZhoubaWiki:HowToSetupSmtpServer&amp;diff=10&amp;oldid=prev</id>
		<title>Garak: Created page with &quot;&lt;!-- Category section --&gt; Category:Zhouba &lt;!-- Contents --&gt; {| align=&quot;right&quot;  | __TOC__  |} = How to set up an outgoing email server =  Here is a guide on getting outgoing...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.zhouba.cz/index.php?title=ZhoubaWiki:HowToSetupSmtpServer&amp;diff=10&amp;oldid=prev"/>
		<updated>2021-05-22T16:19:27Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;!-- Category section --&amp;gt; &lt;a href=&quot;/index.php?title=Category:Zhouba&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Category:Zhouba (page does not exist)&quot;&gt;Category:Zhouba&lt;/a&gt; &amp;lt;!-- Contents --&amp;gt; {| align=&amp;quot;right&amp;quot;  | __TOC__  |} = How to set up an outgoing email server =  Here is a guide on getting outgoing...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;!-- Category section --&amp;gt;&lt;br /&gt;
[[Category:Zhouba]]&lt;br /&gt;
&amp;lt;!-- Contents --&amp;gt;&lt;br /&gt;
{| align=&amp;quot;right&amp;quot;&lt;br /&gt;
 | __TOC__&lt;br /&gt;
 |}&lt;br /&gt;
= How to set up an outgoing email server =&lt;br /&gt;
&lt;br /&gt;
Here is a guide on getting outgoing email services running on Ubuntu using Postfix. This tutorial has been tested on Ubuntu 8.04 VPS from &amp;lt;code&amp;gt;LogicWeb&amp;lt;/code&amp;gt;. Please keep in mind that you have to be logged as root during the whole process.&lt;br /&gt;
&lt;br /&gt;
== Postfix ==&lt;br /&gt;
&lt;br /&gt;
Let’s get core email functionality going with Postfix.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
aptitude install postfix sasl2-bin libsasl2-modules&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will be asked a few questions. Unfortunately, the graphical configuration interface that was automatically launched was a condensed version. Confirm the defaults and run the full graphical configuration utility.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dpkg-reconfigure postfix&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Again, you will be asked some questions:&lt;br /&gt;
&lt;br /&gt;
* General type of mail configuration: '''Internet Site'''&lt;br /&gt;
* System mail name: '''subdomain.hostname.tld''' ''(Use the identity domain and replace the prefix as necessary)''&lt;br /&gt;
* Root and postmaster mail recipient: '''hosting@bugweis.com'''&lt;br /&gt;
* Other destinations to accept mail for: '''subdomain.hostname.tld, localhost''' ''(Use the identity domain)''&lt;br /&gt;
* Force synchronous updates on mail queue: '''No'''&lt;br /&gt;
* Local networks: ''leave default''&lt;br /&gt;
* Use procmail for local delivery: '''Yes'''&lt;br /&gt;
* Mailbox size limit (bytes): '''0'''&lt;br /&gt;
* Local address extension character? ''leave default''&lt;br /&gt;
* Internet protocols to use: '''all'''&lt;br /&gt;
&lt;br /&gt;
Sometimes sendmail is an idiot and keeps running although it was replaced by postfix. In order to avoid problems run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
killall sendmail-mta&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, let’s take care of certificates for TLS. First create a new directory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir /etc/postfix/ssl&lt;br /&gt;
cd /etc/postfix/ssl/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now create a new key and generate a certificate request. You will be asked several questions during this process. Fill them as suggested below. Of course you will have to use domain and name of identity for which this server is being setup.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
openssl genrsa -rand /etc/hosts -out smtpd.key 1024&lt;br /&gt;
chmod 600 smtpd.key&lt;br /&gt;
openssl req -new -key smtpd.key -out smtpd.csr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Example input:''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Country Name (2 letter code) [AU]:GB&lt;br /&gt;
State or Province Name (full name) [Some-State]:&lt;br /&gt;
Locality Name (eg, city) []:London&lt;br /&gt;
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Hostname&lt;br /&gt;
Organizational Unit Name (eg, section) []:&lt;br /&gt;
Common Name (eg, YOUR name) []:subdomain.hostname.tld&lt;br /&gt;
Email Address []:admin@hostname.tld&lt;br /&gt;
&lt;br /&gt;
Please enter the following 'extra' attributes&lt;br /&gt;
to be sent with your certificate request&lt;br /&gt;
A challenge password []:&lt;br /&gt;
An optional company name []:&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we need to self-sign the certificate.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
openssl x509 -req -days 3650 -in smtpd.csr -signkey smtpd.key -out smtpd.crt&lt;br /&gt;
chmod 600 smtpd.key&lt;br /&gt;
rm smtpd.csr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finish configuring Postfix for TLS and SASL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
postconf -e 'smtpd_sasl_local_domain ='&lt;br /&gt;
postconf -e 'smtpd_sasl_auth_enable = yes'&lt;br /&gt;
postconf -e 'smtpd_sasl_security_options = noanonymous'&lt;br /&gt;
postconf -e 'broken_sasl_auth_clients = yes'&lt;br /&gt;
postconf -e 'smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination'&lt;br /&gt;
echo 'pwcheck_method: saslauthd' &amp;gt;&amp;gt; /etc/postfix/sasl/smtpd.conf&lt;br /&gt;
echo 'mech_list: plain login' &amp;gt;&amp;gt; /etc/postfix/sasl/smtpd.conf&lt;br /&gt;
postconf -e 'smtp_use_tls = yes'&lt;br /&gt;
postconf -e 'smtpd_use_tls = yes'&lt;br /&gt;
postconf -e 'smtpd_tls_auth_only = yes'&lt;br /&gt;
postconf -e 'smtp_tls_note_starttls_offer = yes'&lt;br /&gt;
postconf -e 'smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key'&lt;br /&gt;
postconf -e 'smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt'&lt;br /&gt;
postconf -e 'smtpd_tls_loglevel = 1'&lt;br /&gt;
postconf -e 'smtpd_tls_received_header = yes'&lt;br /&gt;
postconf -e 'smtpd_tls_session_cache_timeout = 3600s'&lt;br /&gt;
postconf -e 'tls_random_source = dev:/dev/urandom'&lt;br /&gt;
postconf -e 'home_mailbox = Maildir/'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For some strange reason Postfix config did not use the mail name as the hostname in the SMTP banner so we'll have to configure it manually.&lt;br /&gt;
&amp;lt;c&amp;gt;&lt;br /&gt;
postconf -e 'myhostname = subdomain.hostname.tld'&lt;br /&gt;
&amp;lt;/c&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In case server doesn't have ipv6 interface set &amp;lt;code&amp;gt;inet_protocols&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;c&amp;gt;&lt;br /&gt;
postconf -e 'inet_protocols = ipv4'&lt;br /&gt;
&amp;lt;/c&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you want that SMTP runs on port 465, you have to add this lines to &amp;lt;code&amp;gt;/etc/postfix/master.cf&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
smtps	  inet	n		-		-		-		-		smtpd&lt;br /&gt;
  -o smtpd_tls_wrappermode=yes&lt;br /&gt;
  -o smtpd_sasl_auth_enable=yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, restart Postfix.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/etc/init.d/postfix restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Logging ==&lt;br /&gt;
&lt;br /&gt;
Postfix uses the syslog facility for logging, which means all logs will be stored in &amp;lt;code&amp;gt;/var/log/mail.*&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
These files should be rotated weekly, but pretty much all virtual Ubuntu servers I tested had a weird bug. The weekly syslog script was missing and the log files did not get rotated. If you come across the same problem just install &amp;lt;code&amp;gt;rsyslog&amp;lt;/code&amp;gt; which is newer and better than &amp;lt;code&amp;gt;syslogd&amp;lt;/code&amp;gt; and uses &amp;lt;code&amp;gt;logrotate&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
aptitude install rsyslog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SASL ==&lt;br /&gt;
&lt;br /&gt;
Authentication will be done by saslauthd which will need to be configured to support a chrooted Postfix setup. Edit &amp;lt;code&amp;gt;/etc/default/saslauthd&amp;lt;/code&amp;gt; and add or change the following settings so that they match:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
START=yes&lt;br /&gt;
OPTIONS=&amp;quot;-c -m /var/spool/postfix/var/run/saslauthd&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finish up SASL by creating the chroot directory, adding the postfix user to the sasl group, and then starting saslauthd.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir -p /var/spool/postfix/var/run/saslauthd&lt;br /&gt;
dpkg-statoverride --add root sasl 710 /var/spool/postfix/var/run/saslauthd&lt;br /&gt;
adduser postfix sasl&lt;br /&gt;
/etc/init.d/saslauthd start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
&lt;br /&gt;
At this point, core email services should be up and running. Let’s make sure that you’re in good shape before moving on. First, establish a connection with the mail server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
telnet localhost 25&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After establsihing a connection with the Postfix service, run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ehlo localhost&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
250-STARTTLS&lt;br /&gt;
250-AUTH PLAIN LOGIN&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Type quit to get out.&lt;br /&gt;
&lt;br /&gt;
== Reverse DNS ==&lt;br /&gt;
&lt;br /&gt;
Some mail servers don't accept emails from servers with an invalid or non-existent reverse DNS record. Reverse DNS is linking an IP address to a host name and is maintained by the ISP. Contact the server provider and ask them to set up an RDNS record for the new server (IP -&amp;gt; System mail name). Needless to say the hostname must resolve to the appropriate IP address.&lt;br /&gt;
&lt;br /&gt;
== SPF Record ==&lt;br /&gt;
&lt;br /&gt;
Sender Policy Framework (SPF) is an e-mail validation system designed to prevent e-mail spam. It allows e-mail administrators the ability to specify which Internet hosts are allowed to send e-mail claiming to originate from that domain. From our point of view it's a way to look more legitimate to mail servers, therefore prevent our emails from being marked as spam.&lt;br /&gt;
&lt;br /&gt;
To setup a SPF record you'll have to edit DNS records of sender domain, in our case hostname.tld. Let's presume we want to specify that servers smtp01.hostname.tld and smtp02.hostname.tld can send emails from @hostname.tld. You can do this by adding a new TXT record named &amp;lt;code&amp;gt;hostname.tld&amp;lt;/code&amp;gt; to the DNS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
v=spf1 a:smtp01.hostname.tld a:smtp02.hostname.tld -all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Postfix seem to always use the last defined net interface for sending emails. It is better to specify which interface should be used in the main Postfix configuration file &amp;lt;code&amp;gt;/etc/postfix/main.cf&amp;lt;/code&amp;gt; to avoid later problems with SPF:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
smtp_bind_address = 123.123.123.123 # use IP of smtp01.hostname.tld&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Restart Postfix.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;Note:&amp;lt;/strong&amp;gt;This setting will cause Amavis (see [[ZhoubaWiki:HowToSetupSpamFilterAmavis]]) to reject emails from Postfix:&lt;br /&gt;
&amp;lt;c&amp;gt;&lt;br /&gt;
(!)DENIED ACCESS from IP x.y.z.v, policy bank ''&lt;br /&gt;
&amp;lt;/c&amp;gt;&lt;br /&gt;
Append following setting to &amp;lt;code&amp;gt;/etc/amavis/conf.d/40-policy_banks&amp;lt;/code&amp;gt; to allow messages from bind interface:&lt;br /&gt;
&amp;lt;c&amp;gt;&lt;br /&gt;
# relace x.y.z.v by server IP&lt;br /&gt;
@inet_acl = qw( 127.0.0.1 x.y.z.v [::1])&lt;br /&gt;
&amp;lt;/c&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Detailed information about SPF can be found... on the internet.&lt;br /&gt;
&lt;br /&gt;
== Stripping the 'Received' header ==&lt;br /&gt;
&lt;br /&gt;
=== Variant A ===&lt;br /&gt;
By default Postfix will record the IP address of the client who sent the email. In our case it's the machine where the sendmail script is running. This information can potentially link two Hostname identities together which is something we want to avoid. Therefore we'll configure Postfix to strip the 'Received' header. The &amp;lt;code&amp;gt;/etc/postfix/main.cf&amp;lt;/code&amp;gt; file will have to have a reference to the &amp;lt;code&amp;gt;header_checks&amp;lt;/code&amp;gt; file as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
header_checks = regexp:/etc/postfix/header_checks&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a new file &amp;lt;code&amp;gt;/etc/postfix/header_checks&amp;lt;/code&amp;gt; and add the below line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/^Received: from/	 IGNORE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Apply the new configuration by restarting Postfix.&lt;br /&gt;
&lt;br /&gt;
=== Variant B ===&lt;br /&gt;
This variant is different, instead of removing received header it only replaces received from IP address. It will replace&lt;br /&gt;
all existing Received: from records! Regexp can be latered to taget specific IP only.&lt;br /&gt;
&lt;br /&gt;
First install postfix support for perlc regxexp&lt;br /&gt;
&amp;lt;c bash&amp;gt;&lt;br /&gt;
aptitude install postfix-pcre&lt;br /&gt;
&amp;lt;/c&amp;gt;&lt;br /&gt;
Create file with replacement rules &amp;lt;code&amp;gt;/etc/postfix/smtp_headers_checks&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;c&amp;gt;&lt;br /&gt;
# universal&lt;br /&gt;
/^\s*(Received: from)[^\n]/ REPLACE $1 [127.0.0.1] (localhost [127.0.0.1])&lt;br /&gt;
# Pattern for specific IP replace SERVER IP string&lt;br /&gt;
/^\s*(Received: from)[^\n]*SERVER IP[^\n]*(.*)/ REPLACE $1 [127.0.0.1] (localhost [127.0.0.1])$2&lt;br /&gt;
# Optional, removes headers about agent and client&lt;br /&gt;
#/^\s*User-Agent/		 IGNORE&lt;br /&gt;
#/^\s*X-Enigmail/		 IGNORE&lt;br /&gt;
#/^\s*X-Mailer/			 IGNORE&lt;br /&gt;
#/^\s*X-Originating-IP/  IGNORE&lt;br /&gt;
&amp;lt;/c&amp;gt;&lt;br /&gt;
Update &amp;lt;code&amp;gt;/etc/postfix/main.cf&amp;lt;/code&amp;gt; with&lt;br /&gt;
&amp;lt;c&amp;gt;&lt;br /&gt;
smtp_header_checks = pcre:/etc/postfix/smtp_headers_checks&lt;br /&gt;
&amp;lt;/c&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reload postfix&lt;br /&gt;
&lt;br /&gt;
== Test ==&lt;br /&gt;
&lt;br /&gt;
That's all. Test the new configuration using MX Toolbox.&lt;br /&gt;
&lt;br /&gt;
http://mxtoolbox.com/diagnostic.aspx&lt;br /&gt;
&lt;br /&gt;
...and you can create SMTP connection on your e-mail client. There is example for Thunderbird:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Server Address: IP address for new mail-server&lt;br /&gt;
Port:25&lt;br /&gt;
User name: tester&lt;br /&gt;
Authentization: Password, Secure transmission&lt;br /&gt;
Securely Connection: STARTTLS&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Garak</name></author>
	</entry>
</feed>