0

Since I configured my server, I get these emails frequently in my spam folder :

** truncated **
   ----- The following addresses had permanent fatal errors -----
<[email protected]>
    (reason: 554 5.7.1 <[email protected]>: Relay access denied)
** truncated **

I really have a server called db1.mydomain.com but for a reason I can't find, it's relayed to localhost.mydomain.com.

Of course, I configured aliases :

$: cat /etc/aliases
root: [email protected]
....

and updated it via

$: newaliases

But still, the problem persist.

I don't know what I missed and where to fix it. And everything I tried to search on Google doesn't really helps me (it's about /etc/aliases most of the time).

Thank you for your help. (if you need more details, please ask, I'll add them)

3
  • I'm ok with downvote, but at least I'd like to know why. It's possible I missed something while searching that is obvious for you, but not for me.
    – Cyril N.
    Feb 13, 2014 at 9:03
  • What is the hostname of the machine set to?
    – NickW
    Feb 14, 2014 at 16:16
  • Could you post the relevant log file entries?
    – AnFi
    Feb 16, 2014 at 17:59

2 Answers 2

1
+50

You need to configure sendmail masquerading. If I understand correctly, you want mail from your host db1.mydomain.com to appear to come from mydomain.com

This is easier if you use the m4 macro processor - editing the sendmail.cf quickly gets hairy in my experience, instead edit the sendmail.mc template and rebuild it with something like

m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

Basically, if you start editing the sendmail.cf directly you're on your own. (you also didn't specify what OS you're on so you may have to install the m4 processor and sendmail-cf packages or similar for whatever you're using)

Add these lines to your sendmail.mc:

MASQUERADE_AS(`mydomain.com')dnl
FEATURE(masquerade_envelope)dnl
FEATURE(masquerade_entire_domain)dnl

You only need masquerade_entire_domain if you want to rewrite envelopes from say, a machine host.myotherdomain.com. You probably won't need that, so you can comment it out in the sendmail.mc file by prepending "dnl" to it. (note that the envelope rewrite controls what sendmail uses in SMTP/ESMTP conversations with oher servers, while the MASQUERADE_AS line rewrites the "From:" line that the recipient actually sees)

'dnl', perversely, works in m4 like "#" does in shell scripts. "Delete through newline" IIRC. You can't make this stuff up. It's really disgusting.

If you want sendmail to masquerade mail from root as well (it will normally expose the FQDN for mail from root) you need to change

EXPOSED_USER(`root')dnl

to

dnlEXPOSED_USER(`root')dnl

Ok, now you need to make sure your sending clients are authorized to relay through db1.mydomain.com. Right now for whatever reason your machine is sending with an envelope name of localhost.mydomain.com (I would imagine it's connecting to its loopback address or something, but can't be sure, maybe you've got something screwed up in your DNS) which is not permitted to relay. The simplest and safest way around this is to make a list of all envelope names your authorized machines will present in /etc/mail/relay-domains (in your case, adding localhost.mydomain.com to your relay-domains file, along with any other hosts (FQDNs, again, with proper A and PTR records), and add

FEATURE(relay_hosts_only)dnl

to your sendmail.mc.

Alternately you can use

FEATURE(relay_entire_domain)dnl

Which will permit any host in mydomain.com to relay mail through db1.mydomain.com. Personally I prefer the more restrictive option.

There are many (MANY) other FEATURE macros

You should probably have a look at the docs to get an idea. (sendmail.com) - (although in the time that takes you might be able replace sendmail with postfix...)

Once you're done editing your sendmail.mc generate the sendmail.cf as I described above.

m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

And restart sendmail.

I hope this helps. Google around for "sendmail masquerading" and "controlling sendmail relaying" for lots more info. And don't edit your cf directly, it's a world of pain.

-qb

5
  • I just noticed you tagged your post "Debian". If you can't find m4 or sendmail.mc "apt-get install m4" and "apt-get install sendmail-cf" should fix you up. But I think the sendmail package installs those as dependencies, so you should already have them. Feb 15, 2014 at 11:21
  • Yes I have them. I tried your method but I'm stuck with the error "ERROR: FEATURE() should be before MAILER()" and two other methods. I never changed sendmail.mc before, so this is the original. Any Idea? Can I generate one from scratch ?
    – Cyril N.
    Feb 18, 2014 at 10:03
  • That indicated that your sendmail.mc lines are in the wrong order. Move all your FEATURE lines above your MAILER line. Feb 18, 2014 at 22:28
  • 1
    Ok I give up, sendmail sux. I can't make it work (well, one mail went through, I don't know why and what). I'm gonna replace it by postfix or exim (hadn't made my mind yet). You provided a great and complete answer so I gave you the bounty. Thanks for your help!
    – Cyril N.
    Feb 19, 2014 at 8:51
  • 1
    Yes, sendmail DOES suck. Feb 19, 2014 at 23:41
1

Seems you have not configured your hostname correctly (localhost??)

Make sure your hostname (found with 'hostname' command) is configured to ACCEPT and RELAY email.

You haven't mentioned which MTA you're using, but added a tag for sendmail, so I assume that's what you're using.

Check /etc/mail/sendmail.cf and check for lines beginning with

Cw

and

Fw

statements. Ensure your hostname (found with 'hostname' command) is configured there.

1
  • hostname correctly returns db1.mydomain.com but I want it to send emails to mydomain.com, not db1.mydomain.com. You are right, I'm using sendmail, but will it works if I set Cwmydomain.com ?
    – Cyril N.
    Feb 14, 2014 at 20:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .