Results 1 to 4 of 4

Thread: How to Configure Sendmail as a SMTP Relay to a Smart Host

  1. #1
    Join Date
    Nov 2006
    Location
    Surrey, BC
    Posts
    275
    Blog Entries
    14

    Default How to Configure Sendmail as a SMTP Relay to a Smart Host

    Assuming you have it installed already and are running the default settings. If not, use "apt install sendmail" to get it.

    By default, the SMTP service is configured to listen locally only. Meaning it will only accept mail from within the Linux box. To make it listen from all, we need to modify the "sendmail.mc" file at etc/mail.

    $ sudo nano sendmail.mc

    Locate the DAEMON_OPTIONS entry for SMTP and remove the ADDR=127.0.0.1

    Let's also add the smart host entries. You can add these at the very end:
    define('RELAY_MAILER_ARGS',TCP $h 25')dnl <== Can use 587 or any port allowed by your smart host
    define('SMART_HOST','mail.shaw.ca')dnl

    I use SHAW as that is my ISP. You should probably test that you can relay through your ISP by using the PowerShell 'Send-MailMessage" command. You'll also notice I didn't use the SUBMISSION port as that requires authentication and thus add more complications to the process.

    Exit and save the file.

    Next step is to allow relay from specific hosts. I decided to use specific IP addresses instead of a range to reduce the surface area for attacks. Locate the file "access" in the same location as above.

    $ sudo nano access

    Locate an existing entry starting with "#Connect:" and ends with "Relay". Remove the hashtag and change the IP to match your host's IP but FQDN preferred. Do this with as many hosts you want to relay off this Linux box.

    Exit and save the file.

    Finally to accept the new changes you will need to run the following command:
    $ m4 sendmail.mc > sendmail.cf
    $ systemctl restart sendmail

    In the future, if you only needed to add new hosts, you can just restart the sendmail service. If you modify the "sendmail.mc" file, you have to run the "m4" command for changes to take effect.

    Enjoy!
    Last edited by glen; October 8th, 2023 at 07:08 AM.
    Let's Dance, Punk.

  2. #2
    Join Date
    Nov 2006
    Location
    Surrey, BC
    Posts
    275
    Blog Entries
    14

    Default

    To test sendmail, create a text file with the following entries:

    From: no-reply@domain.ca
    To: someone@domain.ca
    Subject: Testing 123
    This is just a test...

    $ sendmail -vt < test.txt
    Let's Dance, Punk.

  3. #3
    Join Date
    Nov 2006
    Location
    Surrey, BC
    Posts
    275
    Blog Entries
    14

    Default

    $ echo "This is a test" | sendmail someone@domain.com
    Let's Dance, Punk.

  4. #4
    Join Date
    Nov 2006
    Location
    Surrey, BC
    Posts
    275
    Blog Entries
    14

    Default

    I've read that postfix is the preferred choice now for Linux MTA. However I disagree in that if all you are doing is relaying email to a smart host, sendmail is faster and easier to setup. Postfix is better if you are planning to use it as a full blown anti everything SMTP gateway server. Which is what I use for the initial entry of email and after the message passes all the tests, it is forwarded to the mail server.
    Let's Dance, Punk.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •