Mail server: Difference between revisions
(4 intermediate revisions by the same user not shown) | |||
Line 11: | Line 11: | ||
* Linux Foundation Cert Prep: Email Services (Ubuntu) | * Linux Foundation Cert Prep: Email Services (Ubuntu) | ||
= | = SMTP vs POP3, IMAP = | ||
== SMTP (send) == | |||
SMTP (Simple Mail Transfer Protocol) . | |||
'''IMAP''' allows you to access your email wherever you are, from any device. When you read an email message using IMAP, you aren't actually downloading or storing it on your computer; instead, you're reading it from the email service. | There are several alternatives to SMTP (Simple Mail Transfer Protocol) servers for sending and receiving emails, each with its own advantages and use cases. Some of these alternatives include: | ||
* HTTP/HTTPS APIs: | |||
* Third-Party Email APIs: | |||
* WebSockets: | |||
* Message Queues: | |||
* Peer-to-Peer (P2P) Protocols: | |||
* Custom Protocols: In some cases, organizations or projects may develop their custom communication protocols for specific use cases, which can be an alternative to SMTP. | |||
* Direct Socket Connections | |||
Gmail is not an SMTP server; rather, it is an email service provided by Google that uses the '''SMTP protocol''' for sending and receiving emails. Gmail utilizes SMTP (Simple Mail Transfer Protocol) for outgoing email (sending) and other email retrieval protocols like '''IMAP and POP3''' for incoming email (receiving). | |||
When you send an email from your Gmail account, your email client or application communicates with Gmail's SMTP server to send the email. The SMTP server is responsible for delivering your email to the recipient's email server. | |||
== IMAP, POP3, Exchange (receive) == | |||
* [https://support.office.com/en-US/article/What-are-IMAP-and-POP-ca2c5799-49f9-4079-aefe-ddca85d5b1c9?ui=en-US&rs=en-US&ad=US&fromAR=1 What are IMAP and POP?] | |||
* [https://www.howtogeek.com/99423/email-whats-the-difference-in-pop3-imap-and-exchange/ Email: What's the Difference Between POP3, IMAP, and Exchange?] | |||
'''IMAP''' allows you to access your email wherever you are, from any device. When you read an email message using IMAP, you aren't actually downloading or storing it on your computer; instead, you're reading it from the email service. Changes made to emails (read/unread status, folders, etc.) are synchronized across devices because the emails remain on the server. | |||
'''POP''' works by contacting your email service and downloading all of your new messages from it. '''Once they are downloaded onto your PC or Mac, they are deleted from the email service.''' | |||
'''Exchange''' offers the same syncing capabilities as IMAP, plus much more. Exchange is a Microsoft product, giving you the ability to still use Outlook as your email service and benefit from Exchange functionality. | '''Exchange''' offers the same syncing capabilities as IMAP, plus much more. Exchange is a Microsoft product, giving you the ability to still use Outlook as your email service and benefit from Exchange functionality. | ||
Line 62: | Line 80: | ||
* [https://www.geeksforgeeks.org/chfn-command-in-linux-with-examples/ chfn command in Linux with examples] (it works). | * [https://www.geeksforgeeks.org/chfn-command-in-linux-with-examples/ chfn command in Linux with examples] (it works). | ||
* [https://www.serverwatch.com/guides/adding-users-and-aliases-for-postfix/ Adding Users and Aliases for Postfix] | * [https://www.serverwatch.com/guides/adding-users-and-aliases-for-postfix/ Adding Users and Aliases for Postfix] | ||
== /etc/postfix/main.cf == | |||
<ol> | |||
<li>Set Your Domain Name: | |||
<pre> | |||
myhostname = mail.yourdomain.com | |||
</pre> | |||
This parameter specifies the mail server's fully-qualified domain name. | |||
<li>Set the Relayhost: If you want to relay outgoing emails through another SMTP server (common for sending emails to external domains), find the relayhost parameter and set it to the address of the SMTP server you want to relay through. You might also need to configure SMTP authentication for the relay host. | |||
<pre> | |||
relayhost = [smtp.gmail.com]:587 | |||
</pre> | |||
<li>Other Important Parameters: '''mydestination''' (list of domains that your server should consider local), mynetworks (IP addresses or networks allowed to relay through your server), and various security settings. | |||
<li>'''sudo systemctl restart postfix''' | |||
</ol> | |||
== Setup a Local Only SMTP Email Server == | == Setup a Local Only SMTP Email Server == | ||
Line 85: | Line 120: | ||
* https://www.digitalocean.com/community/tutorials/how-to-install-and-setup-postfix-on-ubuntu-14-04 | * https://www.digitalocean.com/community/tutorials/how-to-install-and-setup-postfix-on-ubuntu-14-04 | ||
* [https://www.howtoforge.com/tutorial/how-to-setup-iredmail-server-on-ubuntu-1804/ How to Setup IRedMail Server on Ubuntu 18.04 LTS] | * [https://www.howtoforge.com/tutorial/how-to-setup-iredmail-server-on-ubuntu-1804/ How to Setup IRedMail Server on Ubuntu 18.04 LTS] | ||
* [https://www.rosehosting.com/blog/email-server-on-ubuntu-24-04/ How to Install and Configure an Email Server on Ubuntu 24.04] | |||
== Docker == | == Docker == | ||
Line 164: | Line 200: | ||
== mail command == | == mail command == | ||
<ul> | <ul> | ||
<li>Mailutils includes programs for reading, composing, and sending email, as well as managing mailboxes and user accounts. Mailutils can be used with a variety of mail servers, including Postfix, Exim, Sendmail, and Courier. | <li>'''Mailutils''' includes programs for reading, composing, and sending email, as well as managing mailboxes and user accounts. Mailutils can be used with a variety of mail servers, including Postfix, Exim, Sendmail, and Courier. | ||
<li>Postfix is an open-source mail transfer agent (MTA) that routes and delivers email to accounts that are external to the system. When you install Mailutils on Ubuntu, it will also install Postfix as a dependency if you don't already have some other MTA installed. See [https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-postfix-as-a-send-only-smtp-server-on-ubuntu-20-04 How To Install and Configure Postfix as a Send-Only SMTP Server on Ubuntu 20.04]. | <li>We still need to install Postfix in order to send emails. '''Postfix''' is an open-source mail transfer agent (MTA) that routes and delivers email to accounts that are external to the system. When you install Mailutils on Ubuntu, it will also install Postfix as a dependency if you don't already have some other MTA installed. See [https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-postfix-as-a-send-only-smtp-server-on-ubuntu-20-04 How To Install and Configure Postfix as a Send-Only SMTP Server on Ubuntu 20.04]. | ||
<li>Use '''dpkg -l | grep postfix''' to check if postfix is installed. | <li>Use '''dpkg -l | grep postfix''' to check if postfix is installed. | ||
<li> | |||
<li>To reconfigure postfix, use '''sudo dpkg-reconfigure postfix''' | |||
<li>[https://phoenixnap.com/kb/linux-mail-command How to Use the Linux mail Command] | <li>[https://phoenixnap.com/kb/linux-mail-command How to Use the Linux mail Command] | ||
<li>[https://www.digitalocean.com/community/tutorials/send-email-linux-command-line Send Email in Linux from Command Line] | <li>[https://www.digitalocean.com/community/tutorials/send-email-linux-command-line Send Email in Linux from Command Line]. | ||
* While the command line emails clients are a lot simpler and less computationally intensive, '''you can only use them to send email to personal email domains and not to Gmail or Yahoo domains''' because of extra '''authentication''' required. Also, you cannot receive emails from external SMTP servers. Generally, it’s a lot easier if you use GUI email clients like Thunderbird or Evolution to avoid undelivered emails problem. | |||
<li>Details | <li>Details | ||
<pre> | <pre> | ||
sudo apt install mailutils postfix | sudo apt install mailutils postfix | ||
# OK | # Tab. OK | ||
# | # Default is "Internet Site". OK | ||
# Enter System mail name | # Enter 'System mail name' | ||
# If I enter host.domain.com, emails (to: root@domain.com) can be sent externally | |||
# If I enter domain.com, emails will be sent internally on the local host | |||
# The value will be saved in /etc/postfix/main.cf | |||
</pre> | </pre> | ||
* Configure postfix: sudo nano /etc/postfix/main.cf | * Configure postfix: sudo nano /etc/postfix/main.cf | ||
* Scroll to the bottom and change "inet_interfaces = all" to "inet_interfaces = loopback-only" | * Scroll to the bottom and change "inet_interfaces = all" to "inet_interfaces = loopback-only" | ||
* | ** The reason emails were sent internally or externally is b/c the setting of '''System mail name'''. This will be written to the '''mydestination''' in /etc/postfix/main.cf. Emails sent do anything in '''mydestination''' will be delivered locally. So '''in my case, I need to put hostname.domain.com instead of domain.com in the "System mail name" '''(not the same as the screen explanation). | ||
* echo "This is the body" | mail -s "This is the subject" -a "FROM:[email protected]" [dest address] | * '''systemctl restart postfix''' | ||
* Not work. Check /var/log/mail.log file. It shows the mails were delivered to the local user. ls /var/mail/$USER. Or switch to the user and run "mail". | * '''echo "This is the body" | mail -s "This is the subject" -a "FROM:[email protected]" [dest address] ''' | ||
* It works if I limit the dest address to use my domain name instead of host. | * Not work. Check '''/var/log/mail.log''' file (I'm using Debian 11). It shows the mails were delivered to the local user. ls /var/mail/$USER. Or switch to the user and run "mail". | ||
* It works if I limit the dest address to use my domain name instead of host.domain-name. Not understand if it is b/c I use forwardmail.net. | |||
<li>The '''mydestination''' parameter in the main.cf file of your Postfix configuration specifies a ''list of domains'' for which your mail server will accept mail as the final destination. This parameter helps Postfix determine whether it should deliver incoming email '''locally''' or '''relay''' it to another mail server. | |||
* Local Delivery: When an email is addressed to a domain listed in the mydestination parameter, Postfix will consider that domain as a local destination. This means that Postfix will attempt to deliver the email to a mailbox or user on the local server. For example, if your mydestination parameter includes example.com, and an email is sent to [email protected], Postfix will deliver the email locally. | |||
* Relaying: If a domain is not listed in mydestination, Postfix will treat it as a non-local destination and may relay the email to another mail server based on its routing and transport configurations. This is typically used when your mail server acts as a relay host for domains it doesn't host locally. | |||
* Wildcards: You can use wildcard characters in mydestination to match multiple subdomains or domains. For example, to include all subdomains of example.com, you can use *.example.com. | |||
For example, mydestination = $myhostname, localhost.$mydomain, example.com, *.example.org | |||
* $myhostname refers to the fully-qualified domain name (FQDN) of your mail server. | |||
* localhost.$mydomain specifies that the server should accept mail for the local hostname (e.g., localhost.yourdomain.com). | |||
* example.com is an explicit domain for which your server will accept mail. | |||
* *.example.org is a wildcard entry that matches all subdomains of example.org. | |||
</ul> | </ul> | ||
Latest revision as of 15:15, 1 June 2024
Running an Email Server
- Mail Transport/Transfer Agents (MTAs) - send messages between servers (required)
- Mail Delivery Agents (MDAs) - store messages in the recipient's mailbox (required)
- Mail User Agents (MUA) - software for reading messages
You need a domain name and appropriate MX records in your DNS.
See lynda.com
- Linux: Email Services
- Linux System Engineer: Mail Systems Using Postfix
- Linux Foundation Cert Prep: Email Services (Ubuntu)
SMTP vs POP3, IMAP
SMTP (send)
SMTP (Simple Mail Transfer Protocol) .
There are several alternatives to SMTP (Simple Mail Transfer Protocol) servers for sending and receiving emails, each with its own advantages and use cases. Some of these alternatives include:
- HTTP/HTTPS APIs:
- Third-Party Email APIs:
- WebSockets:
- Message Queues:
- Peer-to-Peer (P2P) Protocols:
- Custom Protocols: In some cases, organizations or projects may develop their custom communication protocols for specific use cases, which can be an alternative to SMTP.
- Direct Socket Connections
Gmail is not an SMTP server; rather, it is an email service provided by Google that uses the SMTP protocol for sending and receiving emails. Gmail utilizes SMTP (Simple Mail Transfer Protocol) for outgoing email (sending) and other email retrieval protocols like IMAP and POP3 for incoming email (receiving).
When you send an email from your Gmail account, your email client or application communicates with Gmail's SMTP server to send the email. The SMTP server is responsible for delivering your email to the recipient's email server.
IMAP, POP3, Exchange (receive)
IMAP allows you to access your email wherever you are, from any device. When you read an email message using IMAP, you aren't actually downloading or storing it on your computer; instead, you're reading it from the email service. Changes made to emails (read/unread status, folders, etc.) are synchronized across devices because the emails remain on the server.
POP works by contacting your email service and downloading all of your new messages from it. Once they are downloaded onto your PC or Mac, they are deleted from the email service.
Exchange offers the same syncing capabilities as IMAP, plus much more. Exchange is a Microsoft product, giving you the ability to still use Outlook as your email service and benefit from Exchange functionality.
Postfix
Introduction to Linux Postfix Architecture for Beginners
Configure Postfix to use Gmail as a Mail Relay
- https://www.howtoforge.com/tutorial/configure-postfix-to-use-gmail-as-a-mail-relay/. Note one comment says to use App Passwords instead of the regular google account password.
- How to Set Up a Mail Agent for Command Line Email
- Easy Email-relay setup with Debian and Postfix using your Gmail account and a similar one How to configure Postfix to use an External SMTP Server
# apt install libsasl2-modules # nano /etc/postfix/main.cf
Delete the line "relayhost =" and add the following to the bottom of the file.
relayhost = [smtp.gmail.com]:587 smtp_sasl_auth_enable = yes smtp_tls_CAfile = /etc/postfix/cacert.pem smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = noanonymous smtp_use_tls = yes
# cat /etc/ssl/certs/VeriSign_Universal_Root_Certification_Authority.pem | tee -a /etc/postfix/cacert.pem # nano /etc/postfix/sasl_passwd
[smtp.gmail.com]:587 [email protected]:APP_PASSWORD
# chmod 400 /etc/postfix/sasl_passwd # /usr/sbin/postmap /etc/postfix/sasl_passwd # /etc/init.d/postfix reload # echo "Subject: Test mail from postfix" | sendmail -v [email protected]
- How to Use the Free Gmail SMTP Server to Send Emails Mar 2023
Adding Users, change user full name for Postfix
- How to set user account Name/Surname in postfix? sudo chfn (Change finger)
- chfn command in Linux with examples (it works).
- Adding Users and Aliases for Postfix
/etc/postfix/main.cf
- Set Your Domain Name:
myhostname = mail.yourdomain.com
This parameter specifies the mail server's fully-qualified domain name.
- Set the Relayhost: If you want to relay outgoing emails through another SMTP server (common for sending emails to external domains), find the relayhost parameter and set it to the address of the SMTP server you want to relay through. You might also need to configure SMTP authentication for the relay host.
relayhost = [smtp.gmail.com]:587
- Other Important Parameters: mydestination (list of domains that your server should consider local), mynetworks (IP addresses or networks allowed to relay through your server), and various security settings.
- sudo systemctl restart postfix
Setup a Local Only SMTP Email Server
- Setup a Local Only SMTP Email Server (Linux, Unix, Mac)
- Local only sendmail that delivers all mail to a directory
# Send to another user in the same machine echo "This is the email body" | sendmail -v -f sender_username receiver_username sudo receiver_username mutt
Send-only SMTP server
- How To Install and Configure Postfix as a Send-Only SMTP Server on Ubuntu 20.04
- How to Configure Postfix as a Send-Only SMTP Server on Ubuntu 20.04
- Installing and Configuring Postfix as a Send-only SMTP Server on Ubuntu 20.04
How to Build an Email Server on Ubuntu Linux
- https://www.linux.com/learn/how-build-email-server-ubuntu-linux, Part 2 & Part 3
- https://help.ubuntu.com/community/Postfix
- https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-postfix-as-a-send-only-smtp-server-on-ubuntu-14-04
- https://www.digitalocean.com/community/tutorials/how-to-install-and-setup-postfix-on-ubuntu-14-04
- How to Setup IRedMail Server on Ubuntu 18.04 LTS
- How to Install and Configure an Email Server on Ubuntu 24.04
Docker
See Docker method
SSL
- How to create a Mail server with SSL/TLS on Linux
- How To Secure Your Linux Email Services with SSL/TLS
- Email forwarding
- Mail forwarding using Sendmail
Raspberry Pi Email Server
Make Your Own Raspberry Pi Email Server
Ways to Keep Your Email Address Hidden
6 Ways to Keep Your Email Address Hidden
DuckDuckGo
DuckDuckGo Can Now Block Your Emails From Being Tracked
Send from google emails on Ubuntu
- How to configure Postfix to use Gmail SMTP on Ubuntu 16.04 / 17.10.
- Configure Postfix to use Gmail as a Mail Relay
- How to configure Postfix to use Gmail SMTP on Ubuntu 18.04 & 16.04
Change your google account to use less secure authentication. Otherwise it won't work and you will receive an email with a subject "Critical security alert" after you try to send out an email.
sudo apt install mailutils sudo nano /etc/postfix/main.cf # no account information sudo nano /etc/postfix/sasl_passwd # contains account information cat /etc/ssl/certs/thawte_Primary_Root_CA.pem | sudo tee -a /etc/postfix/cacert.pem sudo chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db sudo chmod 0600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db sudo apt-get install --reinstall postfix sudo /etc/init.d/postfix restart sudo /etc/init.d/postfix reload echo "Test Email message body" | mail -s "Email test subject" [email protected] # works
We can actually send to other email accounts. For example, we can use mailR package to send emails in R
send.mail(from = "[email protected]", to = c("[email protected]"), replyTo = c("[email protected]"), subject = "Test", body = "test", smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "yourname", passwd = "XX", ssl = TRUE), authenticate = TRUE, send = TRUE)
New domain
If you just bought a new domain name do not forget to fix it's emails!
Use Zoho Mail With Your Domain
How to Migrate from Gmail to Zoho Mail With Your Domain
How to Send an Email with a Different “From” Address in Outlook
How to Send an Email with a Different “From” Address in Outlook. How Email Providers Handle Messages Sent From a Different “From” Address? How Do Scammers Use Fake “From” Addresses?
Bash Script to Send a Mail When ...
Bash Script to Send a Mail About New User Account Creation
Webmail
Install WebMail Lite PHP based Webmail Client on Debian 9.1
You have new mail
What is the "You have new mail" message in Linux/UNIX?
Command line tools
6 Ways to Send Email from the Linux Command Line:
- mailx
- mutt
- mpack
- sendmail
- ssmtp
mail command
- Mailutils includes programs for reading, composing, and sending email, as well as managing mailboxes and user accounts. Mailutils can be used with a variety of mail servers, including Postfix, Exim, Sendmail, and Courier.
- We still need to install Postfix in order to send emails. Postfix is an open-source mail transfer agent (MTA) that routes and delivers email to accounts that are external to the system. When you install Mailutils on Ubuntu, it will also install Postfix as a dependency if you don't already have some other MTA installed. See How To Install and Configure Postfix as a Send-Only SMTP Server on Ubuntu 20.04.
- Use dpkg -l | grep postfix to check if postfix is installed.
- To reconfigure postfix, use sudo dpkg-reconfigure postfix
- How to Use the Linux mail Command
- Send Email in Linux from Command Line.
- While the command line emails clients are a lot simpler and less computationally intensive, you can only use them to send email to personal email domains and not to Gmail or Yahoo domains because of extra authentication required. Also, you cannot receive emails from external SMTP servers. Generally, it’s a lot easier if you use GUI email clients like Thunderbird or Evolution to avoid undelivered emails problem.
- Details
sudo apt install mailutils postfix # Tab. OK # Default is "Internet Site". OK # Enter 'System mail name' # If I enter host.domain.com, emails (to: [email protected]) can be sent externally # If I enter domain.com, emails will be sent internally on the local host # The value will be saved in /etc/postfix/main.cf
- Configure postfix: sudo nano /etc/postfix/main.cf
- Scroll to the bottom and change "inet_interfaces = all" to "inet_interfaces = loopback-only"
- The reason emails were sent internally or externally is b/c the setting of System mail name. This will be written to the mydestination in /etc/postfix/main.cf. Emails sent do anything in mydestination will be delivered locally. So in my case, I need to put hostname.domain.com instead of domain.com in the "System mail name" (not the same as the screen explanation).
- systemctl restart postfix
- echo "This is the body" | mail -s "This is the subject" -a "FROM:[email protected]" [dest address]
- Not work. Check /var/log/mail.log file (I'm using Debian 11). It shows the mails were delivered to the local user. ls /var/mail/$USER. Or switch to the user and run "mail".
- It works if I limit the dest address to use my domain name instead of host.domain-name. Not understand if it is b/c I use forwardmail.net.
- The mydestination parameter in the main.cf file of your Postfix configuration specifies a list of domains for which your mail server will accept mail as the final destination. This parameter helps Postfix determine whether it should deliver incoming email locally or relay it to another mail server.
- Local Delivery: When an email is addressed to a domain listed in the mydestination parameter, Postfix will consider that domain as a local destination. This means that Postfix will attempt to deliver the email to a mailbox or user on the local server. For example, if your mydestination parameter includes example.com, and an email is sent to [email protected], Postfix will deliver the email locally.
- Relaying: If a domain is not listed in mydestination, Postfix will treat it as a non-local destination and may relay the email to another mail server based on its routing and transport configurations. This is typically used when your mail server acts as a relay host for domains it doesn't host locally.
- Wildcards: You can use wildcard characters in mydestination to match multiple subdomains or domains. For example, to include all subdomains of example.com, you can use *.example.com.
- $myhostname refers to the fully-qualified domain name (FQDN) of your mail server.
- localhost.$mydomain specifies that the server should accept mail for the local hostname (e.g., localhost.yourdomain.com).
- example.com is an explicit domain for which your server will accept mail.
- *.example.org is a wildcard entry that matches all subdomains of example.org.
mutt
Mutt is a command line email app for Linux and here's how to set it up
sendemail package
- http://bhfsteve.blogspot.com/2013/03/monitoring-web-page-for-changes-using.html
- sudo apt-get install sendemail
- Usage
sendEmail -f $USERNAME -s smtp.gmail.com:587 \ -xu $USERNAME -xp $PASSWORD -t $USERNAME \ -o tls=yes \ -u "Web page changed" \ -m "Visit it at $URL" sendEmail -f [email protected] -t [email protected] \ -s smtp.gmail.com:587 -xu [email protected] -xp YOURPASSWORD \ -o tls=yes \ -u "Hello from sendEmail" \ -m "How are you? I'm testing sendEmail from the command line."
Modoboa
How to Set Up a Mail Server with Modoboa on Debian 10
Kolab
Install and Configure Kolab Groupware on Ubuntu 16.04 LTS
Criptext: private email service
- https://www.criptext.com/
- https://www.linuxuprising.com/2018/10/criptext-is-new-encrypted-email-service.html
Zimbra
How to Install Zimbra Collaboration Suite 8.8 on Ubuntu
Temporary/Disposable email
Create A Temporary Email From The Command Line With tmpmail