C++ CDO error on smtserver configuration

∥☆過路亽.° 提交于 2019-12-25 08:16:14

问题


Since one week, i search and try many solution find on internet but nothing work. My problem : i must use the componant CDO on a C++ projet to send mail. For this, i take inspiration on many sample found on internet. But for the configuration, only one parameter work, all other send me a first-chance exception when used, but without them, the Send() method catch me an other exception saying me some configuration are missing. NB : All other code like pMsg property are testing and work good.

First i use the import/include below :

#import "..\lib\msado15.dll" rename("ADODB","CDO") rename("EOF", "cdoEOF")
#import "..\lib\cdosys.dll"
#include "cdosysstr.h"
#include "cdosyserr.h"
#include <atlbase.h>
#include <atlimpl.cpp>

In my method, i use this code :

CDO::IMessagePtr pMsg(__uuidof(CDO::Message));
CDO::IConfigurationPtr pConf (__uuidof(CDO::Configuration));
CDO::FieldsPtr pflds;
CDO::FieldPtr pfld;
pflds = pConf->GetFields();

// this first code do same thing.
//pfld = pflds->GetItem(CComVariant(cdoSMTPServer));
//pfld->PutValue(CComVariant((const char*)nomServeurSMTP));
pflds->Item[_variant_t("http://schemas.microsoft.com/cdo/configuration/smtpserver")]->Value = _variant_t((const char*)nomServeurSMTP) ;

//pfld = pflds->GetItem(CComVariant(cdoSendUsingMethod));
//pfld->PutValue(CComVariant((int)CDO::cdoSendUsingPort));
pflds->Item[_variant_t("http://schemas.microsoft.com/cdo/configuration/sendusing")]->Value = _variant_t((int)CDO::cdoSendUsingPort) ;

hr = pflds->Update();

pMsg->PutConfiguration(pConf);

pMsg->PutFrom(emet.AllocSysString());
pMsg->PutTo(dest.AllocSysString());
pMsg->PutSender(emet.AllocSysString());
pMsg->PutSubject(sujetMessage.AllocSysString());

hr = pMsg->Send();

The sendusing configuration is the only did not send me the first-chance exception.

Did i make wrong with this code or to use CDO, must i need some technical prerequisites ?

thanks a lot to helping me. I respond if you need more information to help me solving this problem.

EDIT

I found my FildsPtr have only this 5 configuration : (first four begin with "http://schemas.microsoft.com/cdo/configuration/")

  • languagecode
  • postusing
  • sendusing
  • usemessageresponsetext
  • "urn:schemas:calendar:timezoneid"

I find in my work sendusing parameter but no smtpserver parameter i needed. If possible, how can i add it ?

EDIT 2

I add this code before setting value. The effect is my previous exception disapear. BUT, the Send() method does not work yet and thow me a first-chance exception with hresult -1 without enter in _com_error catch.

pflds->Append(cdoSMTPServer, CDO::adBSTR, sizeof(BSTR), CDO::adFldUnspecified);

来源:https://stackoverflow.com/questions/39657641/c-cdo-error-on-smtserver-configuration

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!