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='mbelugin@gmail.com';
str subject = 'Test';
str attachment = @'c:\AUTOEXEC.BAT';
str url = strFmt(
'mailto:%1?Subject=%2&attachments=""%3""',

recepient,
subject,
attachment
);
;
WinApi::shellExecute(url);
}

12 comments:

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

    ReplyDelete
  2. What version of outlook do you use?

    ReplyDelete
  3. 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)

    ReplyDelete
  4. 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

    ReplyDelete
  5. 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 ?

    ReplyDelete
  6. Can you post an equivalent example using SysOutlook

    ReplyDelete
  7. 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;
    ;

    #sysOutLookComDef

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

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

    collection = sysOutlookMapiFolder.Items();
    type = new COMVariant();
    type.int(#OlItemType_olMailItem);
    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();
    sysOutlookAttachments.add(_source,_type,_position,_displayname);
    item.to("raza.abbas@gmail.com");
    item.subject("test message");
    item.body("test body");
    item.display();
    }

    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.

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

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

    ReplyDelete
  10. 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 ...

    ReplyDelete
  11. 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.

    ReplyDelete
  12. 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

    ReplyDelete