Send HTML email - suggestions for BSFN coding

PPACHECO

Member
Has anyone out there written any business functions to send body messages in html format? If so, please provide some guidance or samples.

Thank you in advance.
 
/**************************************************************************
* Business Function: SendEmailHTML
*
* Description: Send Email With HTML Content
*
* Parameters:
* LPBHVRCOM lpBhvrCom Business Function Communications
* LPVOID lpVoid Void Parameter - DO NOT USE!
* LPDSD559 lpDS Parameter Data Structure Pointer
*
*************************************************************************/

JDEBFRTN (ID) JDEBFWINAPI SendEmailHTML (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSD5598010 lpDS)

{
/************************************************************************
* Variable declarations
************************************************************************/
JCHAR szFrom[257],
szTo[257],
szCC[257],
szSubject[257],
szMessageTextString[30001],
szNameOfAttachmentFile[257],
szAttachmentDisplayText[257],
szNameOfLogFile[257],
cIncludeAttachmentFlag01,
cSendCopyOfEMailToSelfFlag01,
cSetOneWorldErrorFlag01,
cRecordOperInLogFileFlag01,
szOpenMode[5];

int ErrorCode;

int NumAttachments={0};
JDEMailError err=eOK;
JDEMailMessageAtt *smtpAtt = NULL;


/************************************************************************
* Declare structures
************************************************************************/

/************************************************************************
* Declare pointers
************************************************************************/

/************************************************************************
* Check for NULL pointers
************************************************************************/
if ((lpBhvrCom == (LPBHVRCOM) NULL) ||
(lpVoid == (LPVOID) NULL) ||
(lpDS == (LPDSD5598010) NULL))
{
jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("4363"), (LPVOID) NULL);
return ER_ERROR;
}

/************************************************************************
* Set pointers
************************************************************************/

/************************************************************************
* Main Processing
************************************************************************/
/* Copy data structure into local variables */
jdeStrncpy(szFrom, lpDS->szFrom, DIM(szFrom));
jdeStrncpy(szTo, lpDS->szTo, DIM(szTo));
jdeStrncpy(szCC, lpDS->szCC, DIM(szCC));
jdeStrncpy(szSubject, lpDS->szSubject, DIM(szSubject));
jdeStrncpy(szMessageTextString, lpDS->szMessageTextChar30000, DIM(szMessageTextString));
jdeStrncpy(szNameOfAttachmentFile, lpDS->szNameOfAttachmentFile, DIM(szNameOfAttachmentFile));
jdeStrncpy(szAttachmentDisplayText, lpDS->szAttachmentDisplayText, DIM(szAttachmentDisplayText));
jdeStrncpy(szNameOfLogFile, lpDS->szNameOfLogFile, DIM(szNameOfLogFile));
jdeStrncpy(szOpenMode, lpDS->szOpenMode, DIM(szOpenMode));

cIncludeAttachmentFlag01 = lpDS->cIncludeAttachmentFlag01;
cSendCopyOfEMailToSelfFlag01 = lpDS->cSendCopyOfEMailToSelfFlag01;
cSetOneWorldErrorFlag01 = lpDS->cSetOneWorldErrorFlag01;
cRecordOperInLogFileFlag01 = lpDS->cRecordOperInLogFileFlag01;

/*
I0500725_RemoveSurroundingBlanks(szFrom);
I0500725_RemoveSurroundingBlanks(szTo);
I0500725_RemoveSurroundingBlanks(szSubject); */

ErrorCode = 0;

if (jdeStrlen(szFrom) == 0)
ErrorCode = 1;

if (jdeStrlen(szTo) == 0)
ErrorCode += 2;

if (jdeStrlen(szSubject) == 0)
ErrorCode += 4;


if (cIncludeAttachmentFlag01 == _J('1'))
{
if (jdeAccess(szNameOfAttachmentFile, 0)) /* "access" returns 0 if file exists */
{
ErrorCode += 16;
}
else
{
/* Populate attachment structure */
NumAttachments=1;
smtpAtt=malloc(sizeof(JDEMailMessageAtt));
memset (smtpAtt, 0, sizeof(JDEMailMessageAtt)) ;

smtpAtt[0].pVoid=NULL; /* This is always NULL */
jdeStrcpy(smtpAtt[0].filename, lpDS->szNameOfAttachmentFile);
smtpAtt[0].filetype=ATT_FILE;
jdeStrcpy(smtpAtt[0].displayname, lpDS->szAttachmentDisplayText);
}
}
else
{
NumAttachments = 0;
}

if (cSendCopyOfEMailToSelfFlag01 == _J('1') && ErrorCode == 0)
{
if (jdeStrlen(szCC) > 0)
jdeStrcat(szCC, _J(";"));
jdeStrcat(szCC, szFrom);
}

if (ErrorCode == 0)
{
/* Send the E-mail*/

/* SAR 7180331 Use new API old send email is depracated*/
err=JDE_SendEMailSMTPExt(szFrom,
szMessageTextString,
szSubject,
TEXT_HTML,
smtpAtt,
NumAttachments,
szTo,
szCC,
NULL);


if (err != eOK)
ErrorCode += 32;
}

if(err != eOK)
{

if (cSetOneWorldErrorFlag01 == _J('1'))
{
if(err == eSendError)
{
jdeSetGBRError (lpBhvrCom, lpVoid, (ID) 0, _J("033X")); /* Error 033X = One or more addresses are invalid */
}
else
{
jdeSetGBRError (lpBhvrCom, lpVoid, (ID) 0, _J("053X")); /* Error 053X = Email Error - Check your jde.log file */
}
}
}

if (ErrorCode != 0)
if (cRecordOperInLogFileFlag01 == _J('1'))
/* I0500725_WriteErrorsToLogFile(lpBhvrCom, err, ErrorCode, szNameOfLogFile, szOpenMode, szMessageTextString, &lpDS->mnAddressNumber, lpDS->nMailMergeDataRecordNumber); */


if (cIncludeAttachmentFlag01 == _J('1'))
free(smtpAtt); /* free memory */

IntToMathNumeric(ErrorCode, &lpDS->mnErrorCodeReturned);



/************************************************************************
* Function Clean Up
************************************************************************/
return (err == eOK)?ER_SUCCESS:ER_ERROR;
}
 
Thanks for the responce. So basically I do what I do now only format the message text with html tags?
 
Back
Top