# How to configure Sendmail to record the email subject in logs



## hdc (Aug 30, 2019)

Hi All,

The version of FreeBSD is 

```
FreeBSD 12.0-RELEASE-p3 FreeBSD 12.0-RELEASE-p3 GENERIC  amd64
```

So far I can see log from maillog like this:

```
Aug 29 17:08:49 foo sendmail[30651]: x7TF8mLL030651: to=bar, ctladdr=foo (80/80), delay=00:00:01, xdelay=00:00:00, mailer=relay, pri=170288, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (x7TF8nTs030652 Message accepted for delivery)
Aug 29 17:08:49 foo sm-mta[30654]: x7TF8nTs030652: to=bar, delay=00:00:00, xdelay=00:00:00, mailer=esmtp, pri=170532, relay=bar.com, dsn=2.0.0, stat=Sent (<bar> [InternalId=174410031956017, Hostname=bar.com] Queued mail for delivery)
```

How can I add email subject into this log?


----------



## trev (Aug 30, 2019)

Adding this to your .mc file and regenerating .cf should do it:


```
HSubject: $>+LogSubject

LOCAL_RULESETS
SLogSubject
R$*    $: $(log Subject: $1 $) $1
```


----------



## hdc (Sep 11, 2019)

I have added them to my .mc file and make the .cf file but nothing changed.

here is my mc file


```
divert(-1)

divert(0)
VERSIONID(`$FreeBSD: releng/11.0/etc/sendmail/freebsd.mc 285230 2015-07-07 03:00:57Z gshapiro $')
OSTYPE(freebsd6)
DOMAIN(generic)

FEATURE(access_db, `hash -o -T<TMPF> /etc/mail/access')
FEATURE(blacklist_recipients)
FEATURE(local_lmtp)
FEATURE(mailertable, `hash -o /etc/mail/mailertable')
FEATURE(virtusertable, `hash -o /etc/mail/virtusertable')

dnl Enable STARTTLS for receiving email.
define(`CERT_DIR', `/etc/mail/certs')dnl
define(`confSERVER_CERT', `CERT_DIR/host.cert')dnl
define(`confSERVER_KEY', `CERT_DIR/host.key')dnl
define(`confCLIENT_CERT', `CERT_DIR/host.cert')dnl
define(`confCLIENT_KEY', `CERT_DIR/host.key')dnl
define(`confCACERT', `CERT_DIR/cacert.pem')dnl
define(`confCACERT_PATH', `CERT_DIR')dnl
define(`confDH_PARAMETERS', `CERT_DIR/dh.param')dnl

define(`confCW_FILE', `-o /etc/mail/local-host-names')

dnl Enable for both IPv4 and IPv6 (optional)
DAEMON_OPTIONS(`Name=IPv4, Family=inet')
DAEMON_OPTIONS(`Name=IPv6, Family=inet6, Modifiers=O')

define(`confBIND_OPTS', `WorkAroundBrokenAAAA')
define(`confNO_RCPT_ACTION', `add-to-undisclosed')
define(`confPRIVACY_FLAGS', `authwarnings,noexpn,novrfy')
MAILER(local)
MAILER(smtp)

HSubject: $>+LogSubject

LOCAL_RULESETS
SLogSubject
R$*    $: $(log Subject: $1 $) $1
```


----------



## SirDice (Sep 11, 2019)

Run `make install` and `make restart` in /etc/mail. And you may want to review your files, the version string at the top indicates 11.0-RELEASE (releng/11.0), not 12.0-RELEASE (releng/12.0).


----------



## trev (Sep 12, 2019)

Looking at my .mc file I see I actually have:


```
LOCAL_RULESETS
Klog syslog
HSubject: $>+LogSubject
SLogSubject
R$*     $: $(log Subject: $1 $) $1
```

Note: There is a TAB character between R$* and $: in the last line which is necessary.

This yields in the mail log file:

Sep 12 16:13:43 shadow sm-mta[56075]: x8C6DhU6056075: Subject:Testing


----------

