# sendmail and *@*.mydomain.com to one local user



## antolap (May 8, 2012)

Hi,

I would like to know if it's possibile to configure the default sendmail in FreeBSD 9 to catch all emails and put then in a local user mail folder. *I*s it possibile to us*e* the default sendmail or should I change it?

I did this, in Debian with exim4, so DNS is ok for that to work. *W*hich file should I modify?

I read the han*d*book, but I haven't understood if it's possibile o*r* not.

*T*hanks.


----------



## varda (May 8, 2012)

In main .mc file:

```
FEATURE(virtusertable)
```
In virtusertable file:

```
domain.tld  username
```


----------



## antolap (May 10, 2012)

*I*t doesn't work. *I*f I send an email to test@mydomain in /var/log/maillog I read: 
	
	



```
relaying denied
```

Do I have to set also other files?


----------



## usdmatt (May 10, 2012)

I've never found a need to edit the .mc file to support virtusertable, it's in there by default.

The steps I usually do are as follows:

Add the domain to /etc/mail/local-host-names (one domain per line) to tell sendmail it handles mail for the domain. - This is probably why you get relaying denied.

Add the following to /etc/mail/virtusertable
I always put the @ at the start but it may not be required


```
@domain.tld    user
```

Then run the following inside /etc/mail to rebuild & reload.


```
make install restart
```

I would say, however, having a catch-all is rarely a good idea. We see numerous dictionary based spam attacks against domains we host which would end up in massive amounts of email in the catch-all box if we enabled them. As long as you have entries in virtusertable for each email address you do want to use, I see little point in accepting anything else.

I usually do the following:


```
@domain.tld       error:nouser User unknown
sales@domain.tld  user1
info@domain.tld   user1
me@domain.tld     user1
you@domain.tld    user2
etc...
```


----------



## antolap (May 10, 2012)

*I*t doesn't work. *I*f I send an email to user@mydomain I get in maillog: 
	
	



```
User unkown
```

I would like to redirect all mails (directed to anyone) to one local user.


----------



## usdmatt (May 10, 2012)

What exactly do you have in your virtusertable at the moment?

If you want everything to go to one user, you should just have what I put in the first example (the first code block in my last post).

The second example (containing the error:nouser line) is just an example of what I usually do, which is to block the catch-all and set up specific addresses, because I think having a catch-all is a stupid idea (to put it bluntly). I thought maybe you weren't aware that you can set up multiple virtusertable entries for all the addresses you actually want to use.


----------



## antolap (May 10, 2012)

*I*n virtusertable*:*


```
@mydomain.com    tony
```


*I*n local-host-names*:*


```
mydomain.com
```

*W*ith this configuration I can't catch all. I understand it could be a problem with the spam, but I want to catch all. *W*what should I  modify to have sendmai accept all mails?

*F*or example mails to:

one@mydomain.com 
two@mydomain.com 
one-two@mydomain.com 
one@two.mydomain.com
etc.?

thanks


----------



## usdmatt (May 11, 2012)

What you have in your virtusertable and local-host-names should be enough to have the catch-all working.

You did run the following in the /etc/mail directory to rebuild the database files and restart sendmail?


```
make install restart
```

Can you post the output of the following command so I can see what sendmail thinks it should be doing with emails to your domain.


```
sendmail -bv testuser@mydomain.com
```


----------



## antolap (May 11, 2012)

usdmatt said:
			
		

> You did run the following
> 
> 
> ```
> ...



*Y*es, I did*.*



			
				usdmatt said:
			
		

> Can you post the output of the following command so I can see what sendmail thinks it should be doing with emails to your domain.
> 
> 
> ```
> ...



*O*k. *T*his is the output*:*


```
testuser@mydomain.com... User unknown
```


----------



## usdmatt (May 11, 2012)

I'm not really sure what you can be doing wrong here. I've just tried this on a FreeBSD 9 backup machine I have that has never been configured for email previously:


```
backup# sendmail -bv info@mydomain.com
info@mydomain.com... deliverable: mailer esmtp, host mydomain.com., user info@mydomain.com
backup# echo '@mydomain.com matt' >virtusertable
backup# echo 'mydomain.com' >local-host-names
backup# cat virtusertable
@mydomain.com matt
backup# cat local-host-names
mydomain.com
backup# make
/usr/sbin/makemap hash virtusertable.db < virtusertable
chmod 0640 virtusertable.db
backup# sendmail -bv info@mydomain.com
info@mydomain.com... deliverable: mailer local, user matt
```

This shows that to start off with, Sendmail thinks emails to mydomain.com should be delivered externally via esmtp. After adding to the two files mentioned and rebuilding databases, sendmail thinks it's should be delivered to my local user.

The only thing I can think is either 


You have changed some other Sendmail configuration file from standard which has affected the way it works
The username you have put after the space/tab in virtusertable is not a valid local user


----------



## antolap (May 11, 2012)

*O*k, now it's working fine (I didn't underst*an*d what's was wrong).

*M*any thanks*.*


----------

