f



API for Sending HTML Messages

I've already written a wrapper for simple MAPI which lets me send a
mail from my MFC application..

I need to send a HTML message.. which is the best API that i may use
which is simple and which does the job of just opening my outlook with
the desired fields filled.. and just asking for Send confirmation..

I've done some research on Extended MAPI but to no use.. people say
edk.h cannot be used.. since it is old and has many dependency
issues.. so which is the best thing to do this simple task..
0
Charith
6/16/2009 12:59:03 PM
comp.os.programmer.win32 14522 articles. 0 followers. Post Follow

5 Replies
652 Views

Similar Articles

[PageSpeed] 15

On 16 juin, 14:59, Charith <charith.n...@gmail.com> wrote:
> I've already written a wrapper for simple MAPI which lets me send a
> mail from my MFC application..
>
> I need to send a HTML message.. which is the best API that i may use
> which is simple and which does the job of just opening my outlook with
> the desired fields filled.. and just asking for Send confirmation..

One of the ways is with CDO (IMessage::put_HTMLBody())
For example =>

#include <windows.h>
#include "cdosys.tlh"

int main()
{
	CoInitialize(NULL);
	IMessage* pMessage = NULL;
	HRESULT hr = CoCreateInstance(__uuidof(Message), NULL,
CLSCTX_INPROC_SERVER, __uuidof(IMessage), reinterpret_cast<void**>
(&pMessage));

	ADODB::FieldsPtr pFields = NULL;
	hr = pMessage->get_Fields(&pFields);

	ADODB::FieldPtr pField = NULL;
	hr = pFields->get_Item(_variant_t
("urn:schemas:mailheader:to"),&pField);
	hr = pField->put_Value(_variant_t("mailto@mail.com"));
	pField->Release();

	hr = pFields->get_Item(_variant_t
("urn:schemas:mailheader:from"),&pField);
	hr = pField->put_Value(_variant_t("mailfrom@mail.com"));
	pField->Release();

	hr = pFields->get_Item(_variant_t
("urn:schemas:mailheader:sender"),&pField);
	hr = pField->put_Value(_variant_t("Mail From"));
	pField->Release();

	hr = pFields->get_Item(_variant_t
("urn:schemas:mailheader:subject"),&pField);
	hr = pField->put_Value(_variant_t("This is the Subject"));
	pField->Release();
	pField = NULL;

	pFields->Update();
	pFields->Release();
	pFields = NULL;

	IBodyPart* pBodyPart = NULL;
	pBodyPart = pMessage->AddAttachment(L"C:\\foo\\file.txt", L"", L"");
	pBodyPart->Release();
	pBodyPart = NULL;

	char sHTML[1024];
	char sSystemPath[MAX_PATH], sPath[MAX_PATH];
	GetSystemDirectory(sSystemPath, MAX_PATH);
	wsprintf(sPath, "res://%s\\rasdlg.dll/#2/#1678", sSystemPath);
	_variant_t vImage = sPath;
	wsprintf(sHTML,
		 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">"
         "<HTML>"
         "  <BODY>"
         "   <p><FONT COLOR=\"#663399\"><b>This is a Test</b></FONT></
p>"
         "   <p><IMG src=\"%s\"></p>"
         "  </BODY>"
         "</HTML>",
         (char *)(_bstr_t)vImage);

	hr = pMessage->put_HTMLBody((_bstr_t)sHTML);
	hr = pMessage->Send();
	pMessage->Release();

	CoUninitialize();
	return 0;
}
0
Christian
6/16/2009 1:14:35 PM
#include "cdosys.tlh"

tells that there is no file such as cdosys.tlh..

i tried
#import <cdosys.dll>
that couldnt find cdosys.dll

so i tried locating in C:/windows/system32
and i tried #import "C:\windows\system32\cdosys.dll"
It gives me a lot of errors in the generated cdosys.tlh
like

in cdosys.tlh
error C2146: syntax error : missing ';' before identifier
'ActiveConnection'
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
rror C2146: syntax error : missing ';' before identifier
'GetActiveConnection'
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
warning C4183: 'GetActiveConnection': missing return type; assumed to
be a member function returning 'int'
error C2146: syntax error : missing ';' before identifier 'Fields'
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
 error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
error C2146: syntax error : missing ';' before identifier 'GetFields'
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
warning C4183: 'GetFields': missing return type; assumed to be a
member function returning 'int'
error C2146: syntax error : missing ';' before identifier 'Fields'
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
error C2208: 'CDO::Fields' : no members defined using this type
 fatal error C1903: unable to recover from previous error(s); stopping
compilation


Is there any library or header file i am missing to include..?

0
Charith
6/17/2009 8:12:14 AM
On 17 juin, 10:12, Charith <charith.n...@gmail.com> wrote:
> i tried
> #import <cdosys.dll>
> that couldnt find cdosys.dll
>
> so i tried locating in C:/windows/system32
> and i tried #import "C:\windows\system32\cdosys.dll"
> It gives me a lot of errors in the generated cdosys.tlh
> like
>
> in cdosys.tlh
> error C2146: syntax error : missing ';' before identifier
> 'ActiveConnection'

I use :
#import "c:\windows\system32\CDOSYS.DLL" no_namespace auto_search
auto_rename named_guids
0
Christian
6/17/2009 8:42:17 AM
On Jun 17, 1:42=A0pm, Christian ASTOR <casto...@club-internet.fr> wrote:
> On 17 juin, 10:12, Charith <charith.n...@gmail.com> wrote:
>
> > i tried
> > #import <cdosys.dll>
> > that couldnt find cdosys.dll
>
> > so i tried locating in C:/windows/system32
> > and i tried #import "C:\windows\system32\cdosys.dll"
> > It gives me a lot of errors in the generated cdosys.tlh
> > like
>
> > in cdosys.tlh
> > error C2146: syntax error : missing ';' before identifier
> > 'ActiveConnection'
>
> I use :
> #import "c:\windows\system32\CDOSYS.DLL" no_namespace auto_search
> auto_rename named_guids

i tried with these headers
#include <windows.h>
#import "c:\program files\common files\system\ado\msado15.dll"
rename_namespace("ADODB") rename("EOF", "EndOfFile")
#import "c:\windows\system32\CDOSYS.DLL" no_namespace auto_search
auto_rename named_guids
using namespace ADODB;
JSBool JSObj:doSendasEmail( JS_CMD_ARGS )
{
  AfxMessageBox(_T("You've Clicked THis"),MB_OK);
	CoInitialize(NULL);
    IMessage* pMessage =3D NULL;
    HRESULT hr =3D CoCreateInstance(__uuidof(Message), NULL,
CLSCTX_INPROC_SERVER, __uuidof(IMessage), reinterpret_cast<void**>
(&pMessage));

    ADODB::FieldsPtr pFields =3D NULL;
    hr =3D pMessage->get_Fields(&pFields);

    ADODB::FieldPtr pField =3D NULL;
    hr =3D pFields->get_Item(_variant_t
("urn:schemas:mailheader:to"),&pField);
    hr =3D pField->put_Value(_variant_t("mailto@mail.com"));
    pField->Release();

    hr =3D pFields->get_Item(_variant_t
("urn:schemas:mailheader:from"),&pField);
    hr =3D pField->put_Value(_variant_t("mailfrom@mail.com"));
    pField->Release();

    hr =3D pFields->get_Item(_variant_t
("urn:schemas:mailheader:sender"),&pField);
    hr =3D pField->put_Value(_variant_t("Mail From"));
    pField->Release();

    hr =3D pFields->get_Item(_variant_t
("urn:schemas:mailheader:subject"),&pField);
    hr =3D pField->put_Value(_variant_t("This is the Subject"));
    pField->Release();
    pField =3D NULL;

    pFields->Update();
    pFields->Release();
    pFields =3D NULL;

    //IBodyPart* pBodyPart =3D NULL;
    //pBodyPart =3D pMessage->AddAttachment(L"C:\\foo\\file.txt", L"",
L"");
    //pBodyPart->Release();
    //pBodyPart =3D NULL;

    //wchar_t sHTML[1024];
    //wchar_t sSystemPath[MAX_PATH], sPath[MAX_PATH];
    //GetSystemDirectory(sSystemPath, MAX_PATH);
    //wsprintf(sPath, L"C:\Documents and Settings\All Users\Documents
\My Pictures\Sample Pictures\Sunset.jpg", sSystemPath);
    //_variant_t vImage =3D sPath;
    //wsprintf(sHTML,L"'<!DOCTYPE HTML PUBLIC \'-//W3C//DTD HTML 4.0//
EN\'>'   '<HTML>''  <BODY>''   <p><FONT COLOR=3D\'#663399\'><b>This is a
Test</b></FONT></p>' '   <p></p>''  </BODY>''</HTML>'");

    //hr =3D pMessage->put_HTMLBody((_bstr_t)sHTML);
    hr =3D pMessage->Send();
    pMessage->Release();

    CoUninitialize();
	return JS_TRUE;
}


It creates an exception while executing pMessage->Send()

what might be the problem..
and is my header file declaration correct..
0
Charith
6/17/2009 12:10:12 PM
On Jun 17, 1:42=A0pm, Christian ASTOR <casto...@club-internet.fr> wrote:
> On 17 juin, 10:12, Charith <charith.n...@gmail.com> wrote:
>
> > i tried
> > #import <cdosys.dll>
> > that couldnt find cdosys.dll
>
> > so i tried locating in C:/windows/system32
> > and i tried #import "C:\windows\system32\cdosys.dll"
> > It gives me a lot of errors in the generated cdosys.tlh
> > like
>
> > in cdosys.tlh
> > error C2146: syntax error : missing ';' before identifier
> > 'ActiveConnection'
>
> I use :
> #import "c:\windows\system32\CDOSYS.DLL" no_namespace auto_search
> auto_rename named_guids


The pMessage->Send() gives an exception and the exception is IDispatch
Error #32.. no idea what is wrong.. whehter the implementation is
wrong or any other mistake.. need ur help..
thanks..

0
Charith
6/17/2009 1:26:56 PM
Reply: