0

When using CDO to send emails I'm hitting four first-chance exceptions, two each for IMessage::Send() and IMessage::GetStream() (all are unhelpful "long at memory location such and such"). The exceptions happen in code unavailable for me to step through but each one is handled and ultimately I get back an HRESULT of S_OK and the email sends successfully.

I used to hit first-chance exceptions when setting up the configuration like this issue mentions and solved it the same way (used Append() for each item), so I'm thinking there's some setup info I'm missing that's causing the issues with Send()/GetStream().

Here's the gist of what I have:

IMessagePtr message(__uuidof(Message));

IConfigurationPtr config = message->Configuration;
FieldsPtr configFields = config->Fields;

configFields->Item[cdoSendUsingMethod]->Value   = _variant_t(cdoSendUsingPort);
configFields->Append(cdoSMTPServerPort,        DataTypeEnum::adBSTR, SysStringLen(cdoSMTPServerPort),        FieldAttributeEnum::adFldUnspecified, _variant_t(m_lSMTPServerPort));
configFields->Append(cdoSMTPServer,            DataTypeEnum::adBSTR, SysStringLen(cdoSMTPServer),            FieldAttributeEnum::adFldUnspecified, _variant_t(m_sSMTPServer));
configFields->Append(cdoSMTPConnectionTimeout, DataTypeEnum::adBSTR, SysStringLen(cdoSMTPConnectionTimeout), FieldAttributeEnum::adFldUnspecified, _variant_t(m_lSMTPConnectionTimeout));
configFields->Append(cdoSMTPAuthenticate,      DataTypeEnum::adBSTR, SysStringLen(cdoSMTPAuthenticate),      FieldAttributeEnum::adFldUnspecified, _variant_t(cdoBasic));
configFields->Append(cdoSendUserName,          DataTypeEnum::adBSTR, SysStringLen(cdoSendUserName),          FieldAttributeEnum::adFldUnspecified, _variant_t(m_sUserName));
configFields->Append(cdoSendPassword,          DataTypeEnum::adBSTR, SysStringLen(cdoSendPassword),          FieldAttributeEnum::adFldUnspecified, _variant_t(m_sPassword));
configFields->Update();

message->put_To(bsRecipients);
message->put_From(bsFrom);
message->put_Subject(bsSubject);
message->put_TextBody(bsMessage);
message->Send();
_StreamPtr stream = message->GetStream();

This is as far as I see in cdosys.tli

inline HRESULT IMessage::Send ( ) {
    HRESULT _hr = raw_Send();
    if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
    return _hr;
}

inline _StreamPtr IMessage::GetStream ( ) {
    struct _Stream * _result = 0;
    HRESULT _hr = raw_GetStream(&_result);
    if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
    return _StreamPtr(_result, false);
}

Any clue on why I'm seeing these exceptions? Seems odd that the exceptions are used to fix the issues instead of just checking first, not sure why Microsoft would set it up that way.

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
kbake
  • 35
  • 1
  • 6

1 Answers1

0

You may need to configure exception filters in Visual Studio (if you are using VS, which seem to be the case). Go to Main Menu -> Dubug -> Windows -> Exception Settings and uncheck corresponding exception type there so VS won't break when they are thrown.

user7860670
  • 35,849
  • 4
  • 58
  • 84