Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

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

I really have a server called but for a reason I can't find, it's relayed to

Of course, I configured aliases :

$: cat /etc/aliases

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)

share|improve this question
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 '14 at 9:03
What is the hostname of the machine set to? – NickW Feb 14 '14 at 16:16
Could you post the relevant log file entries? – Andrzej A. Filip Feb 16 '14 at 17:59

2 Answers 2

up vote 1 down vote accepted

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

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

m4 /etc/mail/ > /etc/mail/

Basically, if you start editing the 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


You only need masquerade_entire_domain if you want to rewrite envelopes from say, a machine You probably won't need that, so you can comment it out in the 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




Ok, now you need to make sure your sending clients are authorized to relay through Right now for whatever reason your machine is sending with an envelope name of (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 to your relay-domains file, along with any other hosts (FQDNs, again, with proper A and PTR records), and add


to your

Alternately you can use


Which will permit any host in to relay mail through 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. ( - (although in the time that takes you might be able replace sendmail with postfix...)

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

m4 /etc/mail/ > /etc/mail/

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.


share|improve this answer
I just noticed you tagged your post "Debian". If you can't find m4 or "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. – quadruplebucky Feb 15 '14 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 before, so this is the original. Any Idea? Can I generate one from scratch ? – Cyril N. Feb 18 '14 at 10:03
That indicated that your lines are in the wrong order. Move all your FEATURE lines above your MAILER line. – quadruplebucky Feb 18 '14 at 22:28
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 '14 at 8:51
Yes, sendmail DOES suck. – quadruplebucky Feb 19 '14 at 23:41

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/ and check for lines beginning with




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

share|improve this answer
hostname correctly returns but I want it to send emails to, not You are right, I'm using sendmail, but will it works if I set ? – Cyril N. Feb 14 '14 at 20:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.