Hi. I've been trying to send an email using CDO (Collaboration Data Objects) using C++. Unfortunately, there isn't much help on the net; most of the info available is in VB, which I don't know. I found the code listed below on
http://msdn.microsoft.com/en-us/library/aa487412%28EXCHG.65%29.aspx, but I haven't got it to work. I modified what I thought where errors (marked as bold) but now I'm getting a runtime error. I'm using VSPro2008 on WindowsServer2008. The error location is shown in the code.
(Btw, the belowmentioned dlls where successfully located)
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace raw_interfaces_only
#import "c:\windows\system32\cdosys.dll" no_namespace raw_interfaces_only
#include "cdosysstr.h"
#include "cdosyserr.h"
#include <atlbase.h>
#include <atlimpl.cpp>
int main( )
{
CoInitialize(NULL);
HRESULT hr = S_OK;
{
// Create the Configuration object.
CComPtr<IConfiguration> pConf;
hr = pConf.CoCreateInstance(L"CDO.Configuration");
CComPtr<Fields> pFields;
hr = pConf->get_Fields(&
pFields); //was pflds
CComPtr<Field> pfld;
hr = pFields->get_Item(CComVariant(cdoSMTPServer),&pfld);
hr = pfld->put_Value(CComVariant("mailserver"));
hr = pFields->get_Item(CComVariant(cdoSMTPServerPort),&pfld);
//Error
hr = pfld->put_Value(CComVariant((long)67));
hr = pFields->get_Item(CComVariant(cdoSMTPAccountName),&pfld);
hr = pfld->put_Value(CComVariant("George"));
hr = pFields->get_Item(CComVariant(cdoSendEmailAddress),&pfld);
hr = pfld->put_Value(CComVariant("\"MySelf\" <myself@example.com>"));
hr = pFields->get_Item(CComVariant(
cdoSMTPAuthenticate),&pfld);
hr = pfld->put_Value(CComVariant((long)cdoBasic));
hr = pFields->get_Item(CComVariant(cdoSendUserName),&pfld);
hr = pfld->put_Value(CComVariant("domain\\username"));
hr = pFields->get_Item(CComVariant(cdoSendPassword),&pfld);
hr = pfld->put_Value(CComVariant("password"));
hr = pFields->get_Item(CComVariant(cdoSMTPUseSSL),&pfld);
hr = pfld->put_Value(CComVariant(VARIANT_TRUE));
hr = pFields->get_Item(CComVariant(cdoSendUsingMethod),&pfld);
hr = pfld->put_Value(CComVariant((long)cdoSendUsingPort));
hr = pFields->Update();
CComPtr<IMessage> pMsg;
pMsg.CoCreateInstance(L"CDO.Message");
pMsg->putref_Configuration(pConf);
// ... Compose message, add attachments, etc.
pMsg->Send();
}
CoUninitialize();
}
Any help would be greatly appreciated.