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