# Configure default Sendmail on FreeBSD to send ONLY outbound to controlled mail relay



## w3nd377 (Dec 29, 2011)

Looking to be able to send emails with attachments from cron job outbound only from system.  Have no interest in replacing sendmail with ssmtp or postfix.  The system is part of one domain while the email address being submitted to is part of a FQDN domain for email hosted in a remote site.  (System name abc123.closedsite.local and email domain is notrealdomain.net)  We have a controlled mail relay to which we would send the emails for routing into mail system.

Hope to have a cron job kick off script following automated archiving of BIND DNS logs

```
/usr/bin/echo "Nightly tasks status" >x | uuencode status.txt status.txt | cat x - | mailx -s "Task Status for log archive" -r "donotreply@notrealdomain.net" 
"bobsmith@notrealdomain.net"
```

I know that sendmail is installed by default but I do not know how to get a basic config onto the system to allow cron job to send email to mail relay host. Have done the listed things below in an attempt to get it configured but do not know if I am on right path. 

Have done the following:



[cmd=]cp freebsd.mc ${HOST}.mc[/cmd]
[cmd=]cp freebsd.submit.mc ${HOST}.submit.mc[/cmd]

Edited ${HOST}.mc and added 
	
	



```
MASQUERADE_AS(`notrealdomain.netâ€)
FEATURE(`masquerade_envelopeâ€™)
```

Edited /usr/share/sendmail/cf/domain/generic.m4 and did 
	
	



```
dnl # EXPOSED_USER(`rootâ€™)
```

Then [cmd=]make all install[/cmd] from within /etc/mail/.

Restart daemon => [cmd=]make restart[/cmd] from /etc/mail


[cmd=]vi freebsd.submit.mc[/cmd]
	- looked for 
	
	



```
FEATURE(`mspâ€™, `[127.0.0.1]â€˜)dnl
```
	- made it 
	
	



```
FEATURE(`mspâ€™, `[10.10.10.25]â€˜)dnl
```

Then [cmd=]make all install[/cmd] from within /etc/mail/

Restart daemon => [cmd=]make restart[/cmd] from /etc/mail.


Added the following to /etc/rc.conf to ensure that system does not accept inbound emails

```
# Sendmail Settings
sendmail_enable="NO"
```

Followed by:
[cmd=]/etc/rc.d/sendmail restart[/cmd]


 
Edit /etc/mail/sendmail.cf to modify

```
# "Smart" relay host (may be null)
DS
```
to read

```
# "Smart" relay host (may be null)
DSmailrelay.notrealdomain.net
```

Then [cmd=]make all install[/cmd] from within /etc/mail/.

Restart daemon => [cmd=]make restart[/cmd] from /etc/mail.

Am I on right path or have I done too much or too little?


----------



## wblock@ (Dec 29, 2011)

Editing the cf and m4 files directly is discouraged.  Might be necessary sometimes, but...

What you're doing looks complicated, but seems like it could just be done in _hostname_.mc with SMART_HOST.

`# make`
(to generate _hostname_.mc)

Edit and add masquerading and

```
define(`SMART_HOST', `mailrelay.notrealdomain.net')
```

sendmail_submit_enable defaults to on, so that should be fine.  Could still add it to /etc/rc.conf to make it obvious.

Then, in /etc/mail,
`# make all install restart`

The mail relay has to accept mail from this machine, of course.


----------



## w3nd377 (Jan 5, 2012)

I unfortunately may have made it more complicated then was necessary.  Original desire was to simply have system send emails outbound only.  To simplify everything and ensure smooth troubleshooting in future (and to ensure I do not venture too far into the land of "NOOB"), I will reverse all of the modifications I made previously unless you made note of them in your post.  Thanks.


----------



## kisscool-fr (Jan 5, 2012)

Some time ago, I made something like that. I need to send periodic mail reports to my mail account via isp smtp server. 

I procede like that. (starting with a clean /etc/mail/ directory)


```
# cd /etc/mail
# make
# ee fqdn.mc
```

I added these values 


```
MASQUERADE_AS(`mydomain.com')
FEATURE(`masquerade_envelope')
define(`SMART_HOST', `smtp.myisp.com')
```

I added my mail account as root alias. 


```
# ee aliases
```


```
root: root, me@mydomain.com
```

Modified /usr/share/sendmail/cf/domain/generic.m4 like this


```
dnl EXPOSED_USER(`rootâ€™)
```

Then, run :


```
# newaliases
# make
# make install
# make restart
```

And had something working 

It is a lot similar to what you tried, but I don't know maybe some typo or what.


----------

