# Questions about email



## zhangxiaobao (Jul 29, 2014)

Hello,

I am setting up a mail server. I have some experience with FreeBSD in general, but none in mail and sendmail.

My server is at vps.zxb.net (its hostname), and I have an MX record mail.zxb.net pointing to it.

Questions:
Should I send and receive mail using the address user@vps.zxb.net, or user@mail.zxb.net?
If I should do it at mail.zxb.net, how do I set it up? Currently it sends and receives mails at vps.zxb.net, and when mail is sent at mail.zxb.net, it refuses to relay.

Thank you for your help!


----------



## usdmatt (Jul 29, 2014)

Out of the two you've given, I would say user@hostname, so user@vps.zxb.net. However, usually people don't use full hostnames in email addresses, they just use the domain name, such as user@zxb.net. Of course, that's only possible if you actually control the zxb.net domain name.

If you want to use something other than the hostname in the email address, you need to do the following (examples for "zxb.net"):


Add an MX record for the "domain part" of the email address (the bit after the "@", in the case of this example "zxb.net").

```
zxb.net     MX    mail.zxb.net
```
You could also probably just use "zxb.net" here as that already has an A record pointing to the correct place:

```
zxb.net    MX    zxb.net
```

If "mail.zxb.net" is used as an MX record (as above), it needs to be an actual A record, not a CNAME like it is currently.

Delete the mail.zxb.net CNAME record and add:

```
mail.zxb.net    A    50.57.34.52
```

When other users on the Internet email user@zxb.net, they will look up the MX record for "zxb.net", which will return mail.zxb.net, and they will attempt to deliver the message to 50.57.34.62 on port 25.
Add "zxb.net" to your Sendmail configuration. By default Sendmail will only accept email addressed to user@*hostname*. To allow other domains after the @ symbol, you have to tell it which domains to accept:

```
# cd /etc/mail
# make
# vi local-host-names
-- add "zxb.net" to local-host-names --
-- you can add more domains here if you need to, each one on its own line --
# make install restart
```

If you want to use addresses where the left part doesn't map directly to a real local user (such as support@zxb.net), add it to virtusertable:

```
# vi virtusertable
-- add the email address you want on the left, followed by spaces or tabs, then the local user on the right --
# make install restart (can't remember 100% if restart is needed here)
```


(You could actually skip the first two steps in this example, as other servers will just use the A record for "zxb.net" to deliver email if there are no MX records, and the A record for "zxb.net" already points to the correct place. MX would be the "correct" way to do it though and would be required in the majority of cases. You also save clients from doing a useless MX lookup.)


----------



## zhangxiaobao (Jul 30, 2014)

Thank you very much for your detailed explanation!

Now I can receive mail using @zxb.net, but when I send mail (using mail), it's still @vps.zxb.net.

Do I need to change this, and if so, how?


----------



## fonz (Jul 30, 2014)

zhangxiaobao said:
			
		

> Now I can receive mail using @zxb.net, but when I send mail (using mail), it's still @vps.zxb.net.
> 
> Do I need to change this, and if so, how?


It's called masquerading. Add the following to your .mc file:

```
MASQUERADE_AS(`zxb.net')
FEATURE(masquerade_envelope)
FEATURE(allmasquerade)
```
Then rerun `make`, `make install` and `make restart`. Just to be clear: the string on the first line starts with a back quote and ends with a normal one.


----------



## zhangxiaobao (Jul 31, 2014)

Thank you very much!


----------

