5

I have a server with sendmail and I need to send email througt PHP. I have an internal SMTP server on the same subnet, so I configured sendmail with FEATURE(nullclient', mail.server.local')dnl where mail.server.local is solved with an internal IP in /etc/hosts

There is no way that I can change the from address and domain. It's always root@nameoftheserver.localhost.localdomain.

Mar 20 16:18:48 nameoftheserver sm-mta[16402]: v2KFImVi016402: from=<www-data@nameoftheserver.localdomain.local>, size=406, class=0, nrcpts=1, msgid=<201703201518.v2KFImVD016401@nameoftheserver.localdomain.local>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]  

The output of /etc/mail/sendmail.mc:

      (short domain name) $w = nameoftheserver  
  (canonical domain name) $j = nameoftheserver.localdomain.local  
         (subdomain name) $m = localdomain.local  
              (node name) $k = nameoftheserver

How I can change this values?

Kreker
  • 458
  • 4
  • 10
  • 22
  • Where do you see `root@localhost.localdomain`? Your next log line instead shows `www-data@nameoftheserver.localdomain.local` – thrig Mar 20 '17 at 16:14
  • root@ it's in the log if I send from the cli using php, www-data is from the browser. I need to change that. I modified the question – Kreker Mar 20 '17 at 16:17

1 Answers1

6

So, you are trying to change the envelope sender (as PHP's mail() function already handles the "From:" address) with Sendmail. That can be achieved by building a genericstable database to map the input sender address to the address desired.

  1. Create a text file /etc/mail/genericstable containing the mappings,

    www-data       desired.site.address@example.com
    root           root@example.com
    

    where the first value is the original username and the second value is the address desired. Or, if this doesn't work with your node server, the original sender address can also be in format

    www-data@nameoftheserver.localdomain.local  desired.site.address@example.com
    
  2. Create another file /etc/mail/generics-domains containing the domains, separated by newline. (Notice, that the file MUST include your server's canonical domain name.)

  3. Add the corresponding statements to /etc/mail/sendmail.mc:

    FEATURE(`genericstable',`hash -o /etc/mail/genericstable.db')dnl
    GENERICS_DOMAIN_FILE(`/etc/mail/generics-domains')dnl
    
  4. Do the normal procedures after re-configuring Sendmail, e.g.

    cd /etc/mail
    /usr/bin/make
    /usr/bin/newaliases
    systemctl restart sendmail.service
    
Esa Jokinen
  • 46,944
  • 3
  • 83
  • 129
  • didn't workI did it but did not work – Kreker Mar 21 '17 at 10:30
  • Update: forget about my previous message, your solution resolve the problem! Many thanks! – Kreker Mar 22 '17 at 07:33
  • 1
    You’re welcome! I didn't care to reply earlier because the comment didn't add any new information (i.e. error messages or logs) and the solution actually should have worked. – Esa Jokinen Mar 22 '17 at 08:08