Thread: SMTP help! (maybe its my syntax)

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    1

    SMTP help! (maybe its my syntax)

    I'm having tremondous amount of trouble figuring out whats wrong with this program. This is written by somebody else and i dont know any C++. I'm a vb/asp programmer, this is my first time c++. This program works fine with the 'to' field, all I needed to add a cc field. So all i had to do is just duplicate the code for 'to' field and replace it with cc. . When i enter a single recepient for the cc field then the message is sent fine. But when multiple recepients, it doesnt get sent. In the function below, values are sent from the database which holds the message info.
    [b]the problem could be the assignation of value cc to variable fcc, i'm not sure.[b]I would truly appreciate any type of help! Thanks alot!

    Code:
    int CEMailService::PostMessage( CODBC *hODBC2, int MessageID, 
         char *to, char *cc, char *from, char *subject,
         char *body, char *attachment, int style ) 
    { 
       int seeRetCode; 
       int ErrorCode = 0; 
    
       char ErrorMsg[ BUF_256 ]; 
       char fTo  [ BUF_4096 ]; 
       char fCC  [ BUF_4096 ]; 
       char fFrom[ BUF_256 ]; 
    
       char *SmtpServer  = "ip address";  
       char *SmtpTo      = &fTo  [ 0 ]; 
       char *SmtpCC      = &fCC  [ 0 ]; 
       char *SmtpFrom    = &fFrom[ 0 ]; 
       char *SmtpSubject = subject; 
       char *SmtpMessage = body; 
    
       char *SmtpAttach  = attachment; 
    
       char *ch; 
    
       ch = strchr( from, ';' ); 
       if ( ch ) 
           *ch = '\0'; 
    
       ch = strchr( from, ',' ); 
       if ( ch ) 
           *ch = '\0'; 
    
       sprintf( fFrom, "<%s>", Trim(from) ); 
    
       seeRetCode = seeAttach( 1, SEE_KEY_CODE ); 
       if ( seeRetCode < 0 ) 
           return -1; 
    
       seeRetCode = seeIntegerParam(0, SEE_ENABLE_ESMTP, 1 ); 
    
       seeRetCode = seeStringParam (0, SEE_SET_USER,   (LPSTR) "ensadmin" ); 
       seeRetCode = seeStringParam (0, SEE_SET_SECRET, (LPSTR) "##@dm1n##"  ); 
    
       if ( style == 2 ) 
           seeIntegerParam( 0, SEE_QUOTED_PRINTABLE, QUOTED_HTML ); 
       else 
           seeIntegerParam( 0, SEE_QUOTED_PRINTABLE, QUOTED_PLAIN ); 
    
       seeRetCode = seeSmtpConnect( 0, 
                              (LPSTR) SmtpServer,          // SMTP server 
                              (LPSTR) SmtpFrom,            // return email address 
                              (LPSTR) SmtpFrom );          // Reply-To header 
    
       if ( seeRetCode < 0 ) { 
           seeRelease(); 
           return -2; 
       } 
    
       char *token = strtok( to, ";," ); 
       int tokenNumber = 0; 
    
       // If a message has multiple recipients, send to each individually 
     
     sprintf( fCC, "<%s>", trim(cc) ); 
    
       while ( token ) { 
    
           ++tokenNumber; 
           sprintf( fTo, "<%s>", Trim(token) ); 
    
           // if a single message has multiple recipients, a previous send 
           // may have succeeded for some and failed for others.  While 
           // this situation is possible however unlikely, the service will 
           // only attempt a resend of the message to those recipients where 
           // previous send(s) failed. 
    
           if ( !MessageAlreadySent( hODBC2, MessageID, fTo ) ) { 
    
               seeRetCode = seeSendEmail( 0, 
                                   (LPSTR) fTo,                 // To 
                                   //(LPSTR) NULL,                // CC 
           (LPSTR) fCC,                // CC 
                                   (LPSTR) NULL,                // BCC 
                                   (LPSTR) SmtpSubject,         // Subject 
                                   (LPSTR) SmtpMessage,         // HTML message text 
                                   (LPSTR) SmtpAttach );        // MIME attachments ( if any ) 
    
    
               ErrorMsg[ 0 ] = '\0'; 
    
               if ( seeRetCode < 0 ) { 
    
                   seeErrorText( 0, seeRetCode, ErrorMsg, BUF_256 ); 
    
                   ErrorCode = tokenNumber; 
    
               } 
    
               if ( hODBC2 && MessageID != -1 ) { 
    
                   RecordSendAttempt( hODBC2, MessageID, fTo, seeRetCode, ErrorCode, ErrorMsg ); 
    
                   if ( ErrorCode ) 
                       break; 
    
               } 
    
           } 
    
           token = strtok( NULL, ";," ); 
    
       } 
    
       seeClose( 0 ); 
       seeRelease(); 
    
       if ( SmtpAttach && strlen(SmtpAttach)  ) 
           unlink( SmtpAttach ); 
    
       return ErrorCode; 
    
    }

  2. #2
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    this wont help much, but if you split it up into smaller functions, put the huge amount of variables into a couple of structs, it will make it a lot more readable.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM