Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

is there a way to configure sendmail similar to postfix'

always_bcc=bcc@localhost.localdomain

?

share|improve this question

3 Answers 3

up vote 3 down vote accepted

Have a look at this milter: http://www.five-ten-sg.com/sm-archive/

share|improve this answer

You could use MIMEDefang, look for: add_recipient

MIMEDefang is at http://www.mimedefang.org/

share|improve this answer

I was hoping to find a solution that didn't require a milter, but it seems that this is not possible. For just cloning e-mails to a particular mailbox (possibly remote) you could use the milters suggested by others here; I needed to actually create a clone of the SMTP streams to another MTA. The best solution that I found was the mailforward milter. Unfortunately, it didn't seem to work in our Sendmail environment (maybe related to graylisting?)

There's a more complete list of possible solutions at milter.org, including the commercial ($90) milter-bcc, but since the milter API provides a mechanism to add envelope recipients (without making any other changes to the message), I was able to just code up a very minimal milter that adds a fixed recipient to all messages, and then accepts them:

/*
 * Sendmail milter to add an additional (bcc) envelope recipient
 */

#include <stdio.h>
#include <stdlib.h>
#include <sysexits.h>
#include <unistd.h>
#include <sys/stat.h>

#include "libmilter/mfapi.h"

#ifndef bool
# define bool   int
# define TRUE   1
# define FALSE  0
#endif /* ! bool */

char *connsock;
char *bcc;

sfsistat
bccfi_eom(ctx)
     SMFICTX *ctx;
{
    if (smfi_addrcpt(ctx, bcc) != MI_SUCCESS)
        fprintf(stderr, "smfi_addrcpt failed\n");
    return SMFIS_ACCEPT;
}


struct smfiDesc bccfilter =
{
    "add_bcc",  /* filter name */
    SMFI_VERSION,   /* version code -- do not change */
    SMFIF_ADDRCPT,  /* flags */
    NULL,       /* connection info filter */
    NULL,       /* SMTP HELO command filter */
    NULL,       /* envelope sender filter */
    NULL,       /* envelope recipient filter */
    NULL,       /* header filter */
    NULL,       /* end of header */
    NULL,       /* body block filter */
    bccfi_eom,  /* end of message */
    NULL,       /* message aborted */
    NULL,       /* connection cleanup */
#if SMFI_VERSION > 2
    NULL,       /* unknown SMTP commands */
#endif /* SMFI_VERSION > 2 */
#if SMFI_VERSION > 3
    NULL,       /* DATA command */
#endif /* SMFI_VERSION > 3 */
#if SMFI_VERSION > 4
    NULL        /* Negotiate, at the start of each SMTP connection */
#endif /* SMFI_VERSION > 4 */
};

static void
usage(prog)
    char *prog;
{
    fprintf(stderr, "Usage: %s SOCKET_PATH BCC_ADDR\n", prog);
}

int
main(argc, argv)
     int argc;
     char **argv;
{
    char *socket;
    bool rmsocket = FALSE;
    struct stat status;

    if (argc != 3)
    {
        usage(argv[0]);
        exit(EX_USAGE);
    }

    socket = argv[1];
    bcc = argv[2];

    if (smfi_setconn(socket) == MI_FAILURE)
    {
        (void) fprintf(stderr, "smfi_setconn failed\n");
        exit(EX_SOFTWARE);
    }

    /* attempt to remove existing socket, if possible */
    if (stat(socket, &status) == 0 && S_ISSOCK(status.st_mode))
    {
        unlink(socket);
    }

    if (smfi_register(bccfilter) == MI_FAILURE)
    {
        fprintf(stderr, "smfi_register failed\n");
        exit(EX_UNAVAILABLE);
    }

    return smfi_main();
}

You still need to compile and install this (along with initscript or systemd unit to start it up before Sendmail after reboots) and configure Sendmail to use this milter, so it's still rather painful compared to the equivalent add_bcc in postfix (or "unseen" router config in Exim), but that's Sendmail for you.

share|improve this answer

Your Answer

 
discard

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.