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