Basically, this writes a file to the shell in your /mail dir ( under the mud dir), 
then forks ( to make it not lag your mud ), then issues a mail command via the 
system() function.  If your server does not have mail (?), then you might want
to try sendmail, but absolutely no guarantees about the command parameters,
didn't test with that.
Here goes:

/* NOTE:  m_subject needs to be one word only, or it will not work-- no spaces */

/* NOTE:  You will have to replace the MONITOR_DEBUG with whatever monitor
channel you want, or create a MONITOR_DEBUG channel :)  */

/* NOTE:  you will probably want to have a way to store players emails, I used a
new field in pcdata */

/* NOTE: finally, you will have to declare MAIL_DIR, and create it in your
shell.  I used:
  #define MAIL_DIR      "../mail/"
  in merc.h, and create the dir one above your /area dir ( so that you see area,
src, log, mail,  etc when you type ls            
*/


void send_email( const char * m_address, const  char * m_subject, const
char * mfilename )
{
  FILE *mailfp;
  char mailbuf[MSL];
  char delbuf[MSL];
  char dbbuf[MSL];
  int forkval;
  int status;
  
  sprintf( mailbuf, "mail -s \"%s\" %s <%s%s",
     m_subject, m_address, MAIL_DIR, mfilename );
  signal( SIGCHLD, SIG_IGN );
  if ( ( forkval = fork() ) > 0 )
  {
    sprintf( dbbuf, "Just sent email: %s", mailbuf );
                comm_string ( dbbuf, "comm.c");
    return;
  }
  else if ( forkval < 0 )
  {
    sprintf( dbbuf, "Error in fork for sent email: %s", mailbuf );
                comm_string ( dbbuf, "comm.c");
    return;
  }
  if ( ( mailfp = fopen( mfilename, "r" ) ) == NULL )
        {
                fpReserve = fopen( NULL_FILE, "r" );
    exit(0); /* didn't have a valid file to mail */
  }

  fclose( mailfp );
  system( mailbuf );
  sprintf( delbuf, "rm %s%s", MAIL_DIR, mfilename );
  system( delbuf );
  exit(0);
  return;
}

bool save_mail_file( const char * mfilename, char * mtext )
{
  FILE * mailfp;
  char mailfpfilename[MSL];
  fclose( fpReserve );
  sprintf( mailfpfilename, "%s%s", MAIL_DIR, mfilename );
  if ( ( mailfp = fopen( mailfpfilename, "w" ) ) == NULL )
  {
    fpReserve = fopen( NULL_FILE, "r" );
    return FALSE;
  }
  fprintf( mailfp, "%s\n", strip_color( mtext, "@@" ) );
  fflush( mailfp );
  fclose( mailfp ); 
  fpReserve = fopen( NULL_FILE, "r" );
  return TRUE;
}  
  

/* this code donated by Altrag */
char *strip_color(const char *orig, const char *strip)
{
  static char buf[MAX_STRING_LENGTH];
  char *i, *b = buf;
  int slen;

  if (!orig || !strip)
  {
    log_f("strip_out called with NULL param");
    return "!!OUT!!";
  }
  slen = strlen(strip)+1;
  for (i = strstr(orig, strip); i; i = strstr(orig, strip))
  {
    strncpy(b, orig, (i-orig));
    b += i-orig;
    orig = i+slen;
  }
  strcpy(b, orig);
  return buf;
}

Subject: 
           Example of how to use the send_email code
 

/* NOTE: this example assumes that you have already put together a message to
send to the character in the
  char outbuf[MSL];  buffer.
*/

calling:  send_rep_out( ch, outbuf, TRUE, "This is my email subject" );

void send_rep_out( CHAR_DATA * ch, char * outbuf, bool mailme, char * msub )
{
    if ( mailme )
    {
      bool saved_mail = FALSE;
      if (  ( !IS_NPC( ch ) )
         && (  str_cmp( ch->pcdata->email_addy, "notset" ) )  )
      {

        char mailfilename[MSL];
        sprintf( mailfilename, "%s.mail", ch->name );
        saved_mail = save_mail_file( mailfilename, outbuf );
        if ( saved_mail )
        {
          char outbuf2[MSL];
          sprintf( outbuf2, "Email sent to %s", ch->pcdata->email_addy );
          send_to_char( outbuf2, ch );
          send_email( ch->pcdata->email_addy, msub, mailfilename );
        }
        else 
        {
          send_to_char( outbuf, ch );
          send_to_char( "\n\r@@eUNABLE TO SEND SYSTEM MAIL. @@WCheck your sendmail settings.@@N\n\r", ch );

        }
      }
      else
      {
        send_to_char( outbuf, ch );
      }
    }
    else
    {
      send_to_char( outbuf, ch );
    }
}

Subject: 
           Mud email issues
 


I wanted to point out before everyone goes and adds that code to their muds that
it's not complete in any way, and that there are some issues you need to consider:

1) You need some way to make sure that the people use a valid email address, and
one that they own.  Something similar to the subscription confirmation process on 
this list would work well. Just have the mud mail them a password when they
register their mud email account, send the one message, and then store their
typed email in a temp string until they type in the password they receive.  
This is primarily to keep players from entering in someone else's email, then mail
bombing them with spam.  Which, btw would make you and your ISP part of the spam
chain, and cause all sorts of pissed off people...would hate you lose a mud over that.

2) I would log/keep track somehow of how often people are using this system, at
least above a certain threshold, to make sure that they aren't abusing it.  
It's a new issue to me, and I don't know how hackable it is...

Z




