Microsoft Dynamics Ax developer's blog

Thursday, June 21, 2007

Sending attachments using the "mailto:" protocol

It works with Outlook at least. I think this example job is enough

static void Test_MailTo(Args _args)
str recepient='';
str subject = 'Test';
str attachment = @'c:\AUTOEXEC.BAT';
str url = strFmt(



Muhammad Shujaat Siddiqi said...

This does not seem to work saying some switch not correct. When i removed attachment it started working.
Can u help?

Max Belugin said...

What version of outlook do you use?

Unknown said...

The question is whether this is the recommended way to send mail or not ? Could you talk a bit about that ? (I mean compared to SysMail and SysINetMail)

Max Belugin said...

It depends on what do you want.

SysMailer sends E-Mail without wny interaction with user.

Mailto protocol opens new message window and allows to edit the message

Unknown said...

But why use the shell API and not the COM Class Wrappers (SysOutlook* classes) to send mail using much greater customization ? That sort of defeats the purpose of office and axapta integration no ?

Max Belugin said...

Can you post an equivalent example using SysOutlook

Unknown said...

static void Job4(Args _args)
COM sysOutlookApplication;
SysOutlook_NameSpace sysOutlookNameSpace;
SysOutlookMapiFolder sysOutlookMapiFolder;
SysOutlook_Folders sysOutlookFolders;
SysOutlookAttachments sysOutlookAttachments;
SysOutlookAttachment sysOutlookAttachment;
SysOutlook_Items collection;
COM item;
COMVariant type;
COMVariant _source;
COMVariant _type;
COMVariant _position;
COMVariant _displayname;


sysOutlookApplication = new COM("Outlook.Application");
sysOutlookNameSpace = sysOutlookApplication.getNameSpace("MAPI");

sysOutlookFolders = sysOutlookNameSpace.Folders();
sysOutlookMapiFolder = sysOutlookNameSpace.getDefaultFolder(#OlDefaultFolders_olFolderOutbox);

collection = sysOutlookMapiFolder.Items();
type = new COMVariant();;
item = collection.add(type);
sysOutlookAttachments = item.attachments();
//attach sample file
_source = COMVariant::createFromStr(@"C:\sigmatel.log");
_type = COMVariant::createNoValue();
_position = COMVariant::createNoValue();
_displayname = COMVariant::createNoValue();
item.subject("test message");
item.body("test body");

you could so item.send() to send the mail without seeing the message window too. Besides this, there's another class called the SysINetMail which uses Outlook too.

Muhammad Shujaat Siddiqi said...

I am using the same version of Microsoft Outlook that comes with Office 2007. I think it is 12.0...

Max Belugin said...

I am using O2003 so it can be a version depended difference

Unknown said...

Adding attachements from the mailto protocol was considered a security issue that has been fixed in outlook 2007. So no more attachements in the mailto link possible ...

Alex said...

Once my friend opened MS Outlook and showed that all mails were damaged.But fortunately I advised him next utility-converting ost to pst files.Program solved his problems in a minute and free of charge.Besides tool showed how read Microsoft Outlook .ost files and extract all necessary data from it.

Nhel said...

I copied codes of Razza,but I encountered error.

Variable SysOutlook_NameSpace has not been declared.

Do I have to do something with my AX environment.Im using AX 2009 kernel version 5.0.1000.52