[MUD-Dev] Mail from mud Zoran's final Imp

Stephen Zepp zoran at enid.com
Thu Jan 1 13:55:16 CET 1998


Chris Gray wrote:
> 
[snipped my original email function request]
> I have optional stuff in my scenario to do that, and also reading and
> posting to newsgroups. However, it relies on the hosting system having
> a certain setup, with standard programs for sending mail and posting
> news. In my Amiga setup (fairly similar to what UNIX systems use), all
> of the needed stuff is actually specified on the command line to the
> 'sendmail' command.
> 
[snipped Chris's Amiga Imp, thanks, Chris :)]

Thanks for reminding me about this, cleaned it up, then promptly forgot about it.  You can set the
state of mailme in send_rep_out in many ways, I use  mailme = is_name( "mailme", argument ); from
within the caller, which let's players type es <some long output command> mailme.

Here was my final solution with a caller example first:

    send_rep_out( ch, outbuf, mailme, "Estate Help" );


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 );
    }
}



void send_email( const char * m_address, const  char * m_subject, const char * mfilename )
{
  char mailbuf[MSL];
  char delbuf[MSL];
  int forkval;
  sprintf( mailbuf, "mail -s \"%s\" %s <%s%s",
     m_subject, m_address, MAIL_DIR, mfilename );
  if ( ( forkval = fork() ) > 0 )
  {
    sprintf( dbbuf, "Just sent email: %s", mailbuf );
    monitor_chan( dbbuf, MONITOR_DEBUG );
    return;
  }
  else if ( forkval < 0 )
  {
    sprintf( dbbuf, "Error in fork for sent email: %s", mailbuf );
    monitor_chan( dbbuf, MONITOR_DEBUG );
    return;
  }
  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;
}



More information about the mud-dev-archive mailing list