 |
|
SQL Server Tips by Burleson |
Code Highlights
The code is pretty straightforward and uses the various parameters
to set the attributes of the CDO message before it is sent. Some of
the highlights include:
Use is made of the various XP++ macros to access the values in the
‘XP_VARIANT_PARAMETER’ structure. For example:
TCHAR* pszFrom = XP_TTEXT(m_pParameterData[FROM_INDEX].m_Data);
msg->From = pszFrom;
Special consideration needs to be given to the optional parameters.
For example to use the ‘CC’ parameter, the following code is used:
if (m_pParameterData[CC_INDEX].m_bType
!= SRVNULL)
{
TCHAR* pszCC = XP_TTEXT(m_pParameterData[CC_INDEX].m_Data);
XP_ASSERT(pszCC);
msg->CC = pszCC;
}
In addition some parameters, which are declared as optional in the
parameter map become required, depending on the values of other
parameters. For example if Basic Authentication is used to send the
email, then the @User and @Password parameters to the XP should be
achieved. This is accomplished using the following code:
case CDO::cdoBasic:
{
msg->Configuration->Fields->Item[_bstr_t("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")]->Value
= _variant_t(nAuthentication);
bRequiresFieldUpdate = TRUE;
if (m_pParameterData[USER_INDEX].m_bType == SRVNULL)
{
sprintf(szErrorMsg, "%s: \"@User\" parameter is required if using
Basic Authentication", m_szFunctionName);
SendErrorMsg(szErrorMsg);
return FALSE;
}
.
.
The above book excerpt is from:
Super SQL
Server Systems
Turbocharge Database Performance with C++ External Procedures
ISBN:
0-9761573-2-2
Joseph Gama, P. J. Naughter
http://www.rampant-books.com/book_2005_2_sql_server_external_procedures.htm |