Email: Difference between revisions
Line 116: | Line 116: | ||
For all three, replace <code>example.com</code> with your domain and adjust values according to your specific setup or service provider’s guidelines. Setting up these records correctly can significantly improve your email deliverability and protect your domain against misuse. Always test your configuration using tools like Google’s Admin Toolbox or other DMARC, SPF, and DKIM validation tools available online. | For all three, replace <code>example.com</code> with your domain and adjust values according to your specific setup or service provider’s guidelines. Setting up these records correctly can significantly improve your email deliverability and protect your domain against misuse. Always test your configuration using tools like Google’s Admin Toolbox or other DMARC, SPF, and DKIM validation tools available online. | ||
== DKIM on Postfix == | |||
To configure Postfix with DomainKeys Identified Mail (DKIM) to sign outgoing emails, you typically use an external application like OpenDKIM. OpenDKIM provides a method to sign email messages with a DKIM signature based on your private key, enhancing email security and deliverability. Here’s a basic guide to configuring Postfix with DKIM using OpenDKIM: | |||
=== Step 1: Install OpenDKIM === | |||
First, install OpenDKIM and its tools. On Debian/Ubuntu systems, you can do this with: | |||
<source lang="bash">sudo apt-get update | |||
sudo apt-get install opendkim opendkim-tools</source> | |||
=== Step 2: Generate DKIM Keys === | |||
You’ll need to generate a private and public key pair for DKIM. | |||
# Create a directory for your keys: | |||
<source lang="bash">sudo mkdir -p /etc/opendkim/keys/yourdomain.com</source> | |||
<ol start="2" style="list-style-type: decimal;"> | |||
<li>Generate the keys:</li></ol> | |||
<source lang="bash">opendkim-genkey -b 2048 -d yourdomain.com -D /etc/opendkim/keys/yourdomain.com -s mail -v</source> | |||
<ol start="3" style="list-style-type: decimal;"> | |||
<li>Change ownership of the private key to the opendkim user:</li></ol> | |||
<source lang="bash">sudo chown opendkim:opendkim /etc/opendkim/keys/yourdomain.com/mail.private</source> | |||
In this example, <code>yourdomain.com</code> should be replaced with your actual domain, and <code>mail</code> is a selector that will be part of your DKIM record. | |||
=== Step 3: Configure OpenDKIM === | |||
Edit the OpenDKIM main configuration file (<code>/etc/opendkim.conf</code>) to specify your key and signing details. You may need root privileges to edit this file. | |||
# Open <code>/etc/opendkim.conf</code> in your text editor. | |||
# Add or ensure these lines are configured with your domain and key information: | |||
<pre class="conf">KeyTable refile:/etc/opendkim/KeyTable | |||
SigningTable refile:/etc/opendkim/SigningTable | |||
ExternalIgnoreList refile:/etc/opendkim/TrustedHosts | |||
InternalHosts refile:/etc/opendkim/TrustedHosts</pre> | |||
<ol start="3" style="list-style-type: decimal;"> | |||
<li>Create or edit <code>/etc/opendkim/KeyTable</code> and add your domain’s key:</li></ol> | |||
<pre class="conf">mail._domainkey.yourdomain.com yourdomain.com:mail:/etc/opendkim/keys/yourdomain.com/mail.private</pre> | |||
<ol start="4" style="list-style-type: decimal;"> | |||
<li>Create or edit <code>/etc/opendkim/SigningTable</code> and link email addresses to the selector and domain:</li></ol> | |||
<pre class="conf">*@yourdomain.com mail._domainkey.yourdomain.com</pre> | |||
<ol start="5" style="list-style-type: decimal;"> | |||
<li>Create or edit <code>/etc/opendkim/TrustedHosts</code> and add your localhost and domain names to specify which hosts can send mail that will be signed:</li></ol> | |||
<pre class="conf">127.0.0.1 | |||
localhost | |||
yourdomain.com</pre> | |||
=== Step 4: Connect OpenDKIM to Postfix === | |||
Configure Postfix to use OpenDKIM for signing by editing <code>/etc/postfix/main.cf</code> and adding: | |||
<pre class="conf">milter_default_action = accept | |||
milter_protocol = 6 | |||
smtpd_milters = inet:localhost:12301 | |||
non_smtpd_milters = inet:localhost:12301</pre> | |||
Make sure the port (<code>12301</code> in this example) matches the one configured for OpenDKIM. | |||
=== Step 5: Restart and Test === | |||
# Restart OpenDKIM and Postfix to apply changes: | |||
<source lang="bash">sudo systemctl restart opendkim postfix</source> | |||
<ol start="2" style="list-style-type: decimal;"> | |||
<li>Test your DKIM configuration using online tools or by sending an email to a service like <code>check-auth@verifier.port25.com</code>, which will reply with an analysis of your email’s authentication results, including DKIM.</li></ol> | |||
=== Step 6: Publish Your DKIM Public Key === | |||
Don’t forget to publish your DKIM public key in your DNS. You’ll find the public key in a file named <code>mail.txt</code> within your domain’s key directory <code>/etc/opendkim/keys/yourdomain.com</code>. Create a TXT record for <code>mail._domainkey.yourdomain.com</code> with the value provided in that file. | |||
Make sure to replace placeholders like <code>yourdomain.com</code> and <code>mail</code> (if you used a different selector) with your actual domain and selector used during key generation. This guide assumes basic familiarity with Linux server administration and might require adjustments based on your system’s specifics and the domain registrar’s DNS settings interface. |
Revision as of 17:54, 2 April 2024
Links
- Reverse DNS on Lightsail: https://docs.aws.amazon.com/lightsail/latest/userguide/amazon-lightsail-configuring-reverse-dns.html
GPT Recommendation
For a low-volume mail server setup on Debian 12 (Bookworm) that’s primarily used for sending outbound messages from a local instance of MediaWiki, you can opt for a simple yet reliable software stack. The primary goal here is to ensure that emails sent by MediaWiki (e.g., account creation confirmations, notifications) are delivered reliably without setting up a full-fledged mail receiving infrastructure.
Software Stack:
- Postfix: A widely used, open-source Mail Transfer Agent (MTA) that can handle sending outbound emails. It’s relatively straightforward to configure for sending emails and can be secured to prevent unauthorized use.
- Optional: Dovecot: If you ever decide to handle receiving emails (for bounces or administrative purposes), Dovecot is a secure IMAP and POP3 server that integrates well with Postfix. However, for your described use case, Dovecot may not be necessary.
- Certbot (Let’s Encrypt): For securing your connections with TLS, using Certbot to obtain a free SSL certificate from Let’s Encrypt is recommended, especially if you’ll be sending sensitive information.
Basic Setup Instructions:
1. Install Postfix
Update your package list:
sudo apt update
Install Postfix:
sudo apt install postfix
During installation, you’ll be prompted for some basic configuration:
- General type of mail configuration: Choose “Internet Site”.
- System mail name: This should be your domain name (e.g., example.com).
2. Basic Configuration
Edit the main Postfix configuration file
/etc/postfix/main.cf
to ensure it’s set up for sending mail correctly. For a basic setup, you might only need to adjust or verify a few lines:inet_interfaces = loopback-only myhostname = example.com mydestination = mynetworks = 127.0.0.0/8
inet_interfaces
set toloopback-only
ensures Postfix only listens on the localhost interface.myhostname
should be your server’s FQDN.- Clear
mydestination
to prevent Postfix from considering itself the final destination for mail. mynetworks
restricts which IPs can send mail through this server, set it to localhost only for security.
Reload or restart Postfix to apply the changes:
sudo systemctl restart postfix
3. Configure MediaWiki for Email
Ensure MediaWiki is configured to send email through your local Postfix installation. This is usually done in MediaWiki’s LocalSettings.php
:
$wgSMTP = [
'host' => 'localhost',
'IDHost' => 'example.com',
'port' => 25,
'auth' => false,
];
Adjust example.com
to match your domain.
Security and Sending Limits
- IP and Domain Reputation: Ensure your server’s IP and domain have a good reputation. A new IP or one previously used for spam can negatively affect deliverability.
- Reverse DNS: Set up reverse DNS for your server’s IP to match your domain. This is often done through your hosting provider’s control panel.
- SPF Record: Add an SPF record to your domain’s DNS to authorize your server to send email on behalf of your domain.
- DKIM and DMARC: For a low-volume server used as described, DKIM and DMARC are optional but recommended for improving email authenticity.
This setup is sufficient for sending outbound emails from a MediaWiki instance. Remember to monitor your server for any abuse and ensure that it’s not configured as an open relay. For more extensive email needs in the future, consider additional configurations and possibly using external SMTP services designed for high deliverability.
SPF, DKIM, DMARC
Sure, here’s a simplified overview of setting up SPF, DKIM, and DMARC through DNS records. Note that specific values can vary based on your email sending service (e.g., Google Workspace, Office 365, SendGrid, etc.) or if you’re sending emails directly from your own server.
SPF (Sender Policy Framework)
Purpose: SPF allows the owner of a domain to specify which mail servers are permitted to send email on behalf of that domain.
DNS Record Type: TXT
Example Value:
v=spf1 include:_spf.example.com ~all
v=spf1
specifies the SPF version.include:_spf.example.com
tells receiving mail servers to consider the SPF record of_spf.example.com
as part of this domain’s SPF record. Replace_spf.example.com
with the SPF record of your email service provider or your own mail server.~all
is a soft fail for mechanisms not specified in the record. It advises recipients to accept mail whether it passes the SPF check or not but to mark it as suspicious. Use-all
for a hard fail if you’re sure all legitimate sources are listed.
HSL Version
For the HeatSync Labs wiki server, we know the domain (heatsynclabs.wiki) is dedicated to a single purpose, so we can go pretty hardcore. We'll specify that only email from the mx mail.heatsynclabs.wiki should be accepted.
v=spf1 mx:mail.heatsynclabs.wiki -all
DKIM (DomainKeys Identified Mail)
Purpose: DKIM provides a way to validate a domain name identity that is associated with a message through cryptographic authentication.
Configuration: You’ll generate a public/private key pair. The public key goes into your DNS records, and the private key is used by your outgoing email server to sign messages.
DNS Record Type: TXT
Example Value:
v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3...[your_public_key]...
v=DKIM1
specifies the DKIM version.k=rsa
indicates the key type.p=[your_public_key]
is where you paste the actual public key generated by your mail server or email service.
The specific TXT
record name often includes a selector which is a prefix to _domainkey
, like selector1._domainkey.example.com
. The selector is specified by your email system when setting up DKIM.
DMARC (Domain-based Message Authentication, Reporting, and Conformance)
Purpose: DMARC uses SPF and DKIM to determine the legitimacy of an email message, providing instructions to the receiving mail server on what to do if neither of those authentication methods passes. It also specifies how an email sender can receive feedback on messages that pass and/or fail DMARC evaluation.
DNS Record Type: TXT
Example Value:
v=DMARC1; p=reject; rua=mailto:dmarc-reports@example.com
v=DMARC1
specifies the DMARC version.p=reject
is the policy, telling receiving servers to reject messages that fail DMARC checks. Other options includenone
(do nothing, only log the event) andquarantine
(mark as spam).rua=mailto:dmarc-reports@example.com
specifies an email address where aggregate reports should be sent.
For all three, replace example.com
with your domain and adjust values according to your specific setup or service provider’s guidelines. Setting up these records correctly can significantly improve your email deliverability and protect your domain against misuse. Always test your configuration using tools like Google’s Admin Toolbox or other DMARC, SPF, and DKIM validation tools available online.
DKIM on Postfix
To configure Postfix with DomainKeys Identified Mail (DKIM) to sign outgoing emails, you typically use an external application like OpenDKIM. OpenDKIM provides a method to sign email messages with a DKIM signature based on your private key, enhancing email security and deliverability. Here’s a basic guide to configuring Postfix with DKIM using OpenDKIM:
Step 1: Install OpenDKIM
First, install OpenDKIM and its tools. On Debian/Ubuntu systems, you can do this with:
sudo apt-get update
sudo apt-get install opendkim opendkim-tools
Step 2: Generate DKIM Keys
You’ll need to generate a private and public key pair for DKIM.
- Create a directory for your keys:
sudo mkdir -p /etc/opendkim/keys/yourdomain.com
- Generate the keys:
opendkim-genkey -b 2048 -d yourdomain.com -D /etc/opendkim/keys/yourdomain.com -s mail -v
- Change ownership of the private key to the opendkim user:
sudo chown opendkim:opendkim /etc/opendkim/keys/yourdomain.com/mail.private
In this example, yourdomain.com
should be replaced with your actual domain, and mail
is a selector that will be part of your DKIM record.
Step 3: Configure OpenDKIM
Edit the OpenDKIM main configuration file (/etc/opendkim.conf
) to specify your key and signing details. You may need root privileges to edit this file.
- Open
/etc/opendkim.conf
in your text editor. - Add or ensure these lines are configured with your domain and key information:
KeyTable refile:/etc/opendkim/KeyTable SigningTable refile:/etc/opendkim/SigningTable ExternalIgnoreList refile:/etc/opendkim/TrustedHosts InternalHosts refile:/etc/opendkim/TrustedHosts
- Create or edit
/etc/opendkim/KeyTable
and add your domain’s key:
mail._domainkey.yourdomain.com yourdomain.com:mail:/etc/opendkim/keys/yourdomain.com/mail.private
- Create or edit
/etc/opendkim/SigningTable
and link email addresses to the selector and domain:
*@yourdomain.com mail._domainkey.yourdomain.com
- Create or edit
/etc/opendkim/TrustedHosts
and add your localhost and domain names to specify which hosts can send mail that will be signed:
127.0.0.1 localhost yourdomain.com
Step 4: Connect OpenDKIM to Postfix
Configure Postfix to use OpenDKIM for signing by editing /etc/postfix/main.cf
and adding:
milter_default_action = accept milter_protocol = 6 smtpd_milters = inet:localhost:12301 non_smtpd_milters = inet:localhost:12301
Make sure the port (12301
in this example) matches the one configured for OpenDKIM.
Step 5: Restart and Test
- Restart OpenDKIM and Postfix to apply changes:
sudo systemctl restart opendkim postfix
- Test your DKIM configuration using online tools or by sending an email to a service like
check-auth@verifier.port25.com
, which will reply with an analysis of your email’s authentication results, including DKIM.
Step 6: Publish Your DKIM Public Key
Don’t forget to publish your DKIM public key in your DNS. You’ll find the public key in a file named mail.txt
within your domain’s key directory /etc/opendkim/keys/yourdomain.com
. Create a TXT record for mail._domainkey.yourdomain.com
with the value provided in that file.
Make sure to replace placeholders like yourdomain.com
and mail
(if you used a different selector) with your actual domain and selector used during key generation. This guide assumes basic familiarity with Linux server administration and might require adjustments based on your system’s specifics and the domain registrar’s DNS settings interface.