My linux world » srv-mail

srv-mail


Contents

Prerequiste

I assume that you have a Centos installation.

SMTP

You can copy/paste this script and use it to configure automatically your server.

  1. #!/bin/bash
  2.  
  3. echo "install postfix"
  4. dnf -y install postfix
  5. dnf -y remove sendmail # make postfix the default MTA
  6.  
  7. echo "start service"
  8. systemctl start postfix.service
  9.  
  10. echo "configure postfix"
  11.  
  12. # comments all:
  13. sed -i "s/^\(inet_interfaces = \)/#\1/" /etc/postfix/main.cf
  14. sed -i "s/^\(mydestination = \)/#\1/" /etc/postfix/main.cf
  15.  
  16. # remove comments:
  17. sed -i "s/^#\(inet_interfaces = all\)/\1/" /etc/postfix/main.cf
  18. sed -i "s/^#\(home_mailbox = Maildir\/\)/\1/" /etc/postfix/main.cf
  19. sed -i "s/^#\(mydestination = \$myhostname, localhost.\$mydomain, localhost, \$mydomain\)$/\1/" /etc/postfix/main.cf
  20.  
  21. echo "reload postfix"
  22. systemctl reload postfix.service
  23.  
  24. echo "add service smtp (port 25) to firewall"
  25. firewall-cmd --permanent --add-service smtp
  26. firewall-cmd --reload
  27.  

Testing email

Inside the server

First, we create our email file ’email.txt’:

Subject: my subject
my message

Then, send it:

sendmail -v example@gmail.com < email.txt

Outside the server

$> telnet srv-mail 25
$> 
helo srv-mail
mail from:<noreply@gmail.com>
rcpt to:<my-email@gmail.com>
data
From: noreply@gmail.com
Subject: test mail from command line
 
this is my tiny message
sent from linux
.

IMAP / POP

You can copy/paste this script and use it to configure automatically your server.

  1. #!/bin/bash
  2.  
  3. echo "install dovecot"
  4. dnf -y install dovecot
  5.  
  6. echo "configure dovecot"
  7. sed -i "s/^#\(protocols\s*=\)/\1/" /etc/dovecot/dovecot.conf
  8.  
  9. echo "start service dovecot on boot"
  10. systemctl enable dovecot.service
  11.  
  12. echo "start service"
  13. systemctl start dovecot.service
  14.  
  15.  
  16. echo "open pop3 port (i.e 110) and imap (i.e. 143)"
  17. firewall-cmd --permanent --add-service dovecot

Copyright © 2023 My linux world - by Marc RABAHI
Design by Marc RABAHI and encelades.

Fork me on GitHub