sending email using CDO

Jul 9, 2009 at 3:12pm
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.
Last edited on Jul 9, 2009 at 7:29pm
Jul 10, 2009 at 7:59am
> Unfortunately, there isn't much help on the net

Because you didn't search correctly...
There are plenty of samples on Google (Groups) ( Win32 ng http://tinyurl.com/cmhb5g and others) for years (C and C++ mainly, without ATL)
Last edited on Jul 10, 2009 at 8:00am
Jul 10, 2009 at 11:49am
Thx for the reply. I found a couple more samples on the link provided, but still no luck at getting them to work. CDO has been installed and the SMTP server has been installed as well (even though I'm not sure if this is a requirement). I've successfully compiled and run codes using MAPI but had no luck with CDO yet.
Any help would be greatly appreciated.
Topic archived. No new replies allowed.