如何将文件拖放到 .MAPIMail [英] How to drop files onto .MAPIMail

查看:37
本文介绍了如何将文件拖放到 .MAPIMail的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一些文件(或 shell 文件对象),我如何使用它们调用 .MAPIMail 注册的 shell 扩展处理程序?

<小时>

问题

我在电脑上有一些文件:

  • C:\Users\ian\AppData\Local\Temp\Contoso_Invoice_141174.pdf
  • C:\Users\ian\AppData\Local\Temp\Contoso_Invoice_141173.pdf
  • C:\Users\ian\AppData\Local\Temp\Contoso_Invoice_141171.pdf

我想做的编程相当于将它们放在 .MAPIMail 注册处理程序上:

发送到文件夹的邮件收件人选项实际上是一个特殊的注册.MAPIMail扩展名:

哪个是系统注册的文件类型:

HKEY_CLASSES_ROOT\.mapimail

如何调用一个临时的 .mapimail 文件?

你不能直接查看注册表吗?

现在,我可能是一个糟糕的开发人员,并且拼写注册表,.mapimail 条目的默认值:

CLSID\{9E56BE60-C50F-11CF-9A2C-00A0C90A90CE}

提取 clsid {9E56BE60-C50F-11CF-9A2C-00A0C90A90CE},并确认类已注册:

HKEY_CLASSES_ROOT\CLSID\{9E56BE60-C50F-11CF-9A2C-00A0C90A90CE}(默认)= 桌面快捷方式\InProcServer32(默认)= %SystemRoot%\System32\sendmail.dll

并使用 CoCreateInstance 创建该 COM 对象:

IUnknown unk = CreateComObject("{9E56BE60-C50F-11CF-9A2C-00A0C90A90CE}");

然后我处于一个未记录、不受支持的世界,我不知道我必须QueryInterface 使用什么接口,以及以什么顺序调用什么方法.

所以我们只剩下 shell 编程了

我想要的是可能涉及 shell 的东西(伪代码):

IShellFolder 桌面;OleCheck(SHGetDesktopFolder(out desktop));列表pidls = new List();乌龙骗子 = 0;ULONG dwAttributes = 0;PIDL pidl;foreach(文件中的字符串文件名)做{OleCheck(desktop.ParseDisplayName(0, nil, filename, out chEaten, out pidl, ref dwAttributes));pidls.Add(pidl);}//获取temp文件夹的shell文件夹IShellFolder tempShellFolder;desktop.ParseDisplayName(0, nil, GetTemporaryPath, out chEaten, out pidl, ref dwAttributes));desktop.BindToObject(pidl, nil, IShellFolder, tempShellFolder);//我不知道我在做什么;只是将看起来合理的代码放在一起//实际上没有人会读到这个IDontCare 上下文;tempShellFolder.GetUIObjectOf(0, pidls.Count, pidls, IDontCareAnymore, nil, ref context);

除了所有代码都依赖于上下文菜单的存在,而我没有.没有人说.MAPIMail 必须在任何上下文发送到 菜单中.

我问的是如何将文件放到 .mapimail 文件中.

还有我的天.

为什么不直接使用 MAPI?

因为当您是在安装了 Office 64 位的 Windows 64 位上运行的 32 位应用程序时,没有安装 MAPI 客户端.所以我需要能够完成用户已经可以做到的事情.

解决方案

虽然它没有回答我的问题,但 Raymond 指出这是一个愚蠢的问题.任何头脑正常的人都不应该尝试向收件人发送邮件.但我很绝望!

事实证明我并没有完全卡住.虽然从 32 位应用程序(反之亦然)处理 64 位 Outlook(MAPI 提供程序)时有一个bitness噩梦,但有一个.

如果我使用只是 MapiSendMail,并且没有其他 MAPI 函数,那么跨越 32 位/64 位障碍是安全的.来自 在 32 位和 64 位平台上构建 MAPI 应用程序:

<块引用>

32 位 MAPI 应用程序和 64 位 Outlook

不支持在安装了 64 位 Outlook 和 64 位 Windows 的计算机上运行 32 位 MAPI 应用程序.应用程序开发人员必须将应用程序更新和重建为 64 位平台的 64 位应用程序.这是因为 32 位应用程序无法加载 64 位 Msmapi32.dll 文件.应用程序开发人员必须合并少量 API 更改才能成功地为 64 位环境构建代码.MAPI 头文件已更新为这些更改以支持 64 位平台.您可以在 Outlook 2010 下载这些头文件:MAPI 头文件.开发人员可以使用同一组 MAPI 头文件来构建 32 位和 64 位 MAPI 应用程序

这听起来像是失去了所有希望.但是,在 Windows 7 上:

<块引用>

异常:MAPISendMail

但是,所有 Simple MAPI 和 MAPI 元素之间的一个函数调用 MAPISendMail 在 Windows-32-bit-on-Windows-64-bit (WOW64) 或 Windows-64-bit-on-Windows-32-bit (WOW32) 场景,不会导致上述警报.此 WOW64 方案仅适用于 Windows 7.图 2 显示了一个 WOW64 方案,其中 32 位 MAPI 应用程序在安装有 64 位 Windows 7 的计算机上调用 MAPISendMail.在此方案中,MAPI 库进行 COM 调用以启动 64 位 Fixmapi 应用程序.Fixmapi 应用程序隐式链接到 MAPI 库,该库将函数调用路由到 Windows MAPI 存根,后者又将调用转发到 Outlook MAPI 存根,从而使 MAPISendMail 函数调用成功.

因此,作为 Delphi Jedi 用户,他们的简单发送电子邮件功能将失败(因为他们使用过多的 MAPI).所以我必须创建自己的:

procedure MapiSimpleSendMail(slFiles: TStrings; ToEmailAddress: string=''; ToName: string='');无功mapiMessage: TMapiMessage;标志:长字;//发件人姓名:AnsiString;//senderEmailAddress: AnsiString;电子邮件主题:AnsiString;电子邮件正文:AnsiString;//发件人:TMapiRecipDesc;收件人:TMapiRecipDesc 的打包数组;附件:TMapiFileDesc 的打包数组;i:整数;小时:红衣主教;es:字符串;常量MAPI_E_UNICODE_NOT_SUPPORTED = 27;//Windows 8. 指定了 MAPI_FORCE_UNICODE 标志,不支持 Unicode.开始ZeroMemory(@mapiMessage, SizeOf(mapiMessage));{ 发件人姓名:= '';发件人电子邮件地址:= '';ZeroMemory(@sender, sizeof(sender));sender.ulRecipClass := MAPI_ORIG;//MAPI_TO、MAPI_CC、MAPI_BCC、MAPI_ORIGsender.lpszName := PAnsiChar(senderName);sender.lpszAddress := PAnsiChar(senderEmailAddress);}mapiMessage.lpOriginator := nil;//PMapiRecipDesc;{ 发起者描述符}如果 ToEmailAddress <>'' 然后开始SetLength(收件人,1);收件人[0].ulRecipClass := MAPI_TO;收件人[0].lpszName := LPSTR(ToName);收件人[0].lpszAddress := LPSTR(ToEmailAddress);mapiMessage.lpRecips := @recipients[0];//NULL 值表示没有收件人.此外,当此成员为 NULL 时,nRecipCount 成员必须为零.mapiMessage.nRecipCount := 1;结尾别的开始mapiMessage.lpRecips := nil;//NULL 值表示没有收件人.此外,当该成员为 NULL 时,nRecipCount 成员必须为零.mapiMessage.nRecipCount := 0;结尾;mapiMessage.lpszMessageType := nil;如果 slFiles.Count >0 那么开始emailSubject := '电子邮件:';电子邮件正文:=' '+#13#10+//是的,shell确实创建了一个前导行为十个空格的空白邮件'您的消息已准备好与以下文件或链接附件一起发送:'+#13#10;SetLength(附件,slFiles.Count);对于 i := 0 到 slFiles.Count-1 做开始附件[i].ulReserved := 0;//红衣主教;{ 保留以备将来使用(必须为 0)}附件[i].flFlags := 0;//红衣主教;{标志}附件[i].nPosition := $FFFFFFFF;//红衣主教;{ 文本中的字符将被附件替换 }附件[i].lpszPathName := PAnsiChar(slFiles[i]);{ 附件文件全路径名}附件[i].lpszFileName := nil;//LPSTR;{ 原始文件名(可选)}附件[i].lpFileType := nil;//指针;{ 附件文件类型(可以是 lpMapiFileTagExt)}如果我>0 那么emailSubject := emailSubject+', ';emailSubject := emailSubject+ExtractFileName(slFiles[i]);emailBody := emailBody+#13#10+ExtractFileName(slFiles[i]);结尾;emailBody := emailBody+#13#10+#13#10+#13#10+'注意:为了防止计算机病毒,电子邮件程序可能会阻止发送或接收某些类型的文件附件.检查您的电子邮件安全设置以确定如何处理附件.';mapiMessage.lpFiles := @attachments[0];mapiMessage.nFileCount := slFiles.Count;结尾别的开始电子邮件主题:= '';电子邮件正文:= '';mapiMessage.lpFiles := nil;mapiMessage.nFileCount := 0;结尾;{主题电子邮件:4388_888871544_MVM_10.tmp、amt3.log、swtag.log、wct845C.tmp、~vs1830.sql身体<-- 十个空格您的邮件已准备好与以下文件或链接附件一起发送:4388_888871544_MVM_10.tmpamt3.logswtag.logwct845C.tmp~vs1830.sql注意:为防止计算机病毒,电子邮件程序可能会阻止发送或接收某些类型的文件附件.检查您的电子邮件安全设置以确定如何处理附件.}mapiMessage.lpszSubject := PAnsiChar(emailSubject);mapiMessage.lpszNoteText := PAnsiChar(emailBody);标志:= MAPI_DIALOG;hr := Mapi.MapiSendMail(0, 0, mapiMessage, flags, 0);案例小时SUCCESS_SUCCESS: {nop};//调用成功,发送消息.MAPI_E_AMBIGUOUS_RECIPIENT:开始//es := '一个接收者匹配了多个接收者描述符结构并且未设置 MAPI_DIALOG.没有消息发送.';raise Exception.CreateFmt('Error %s 发送电子邮件:%s', ['MAPI_E_AMBIGUOUS_RECIPIENT', SysErrorMessage(hr)]);结尾;MAPI_E_ATTACHMENT_NOT_FOUND:开始//未找到指定的附件.没有发送任何消息.raise Exception.CreateFmt('Error %s 发送电子邮件:%s', ['MAPI_E_ATTACHMENT_NOT_FOUND', SysErrorMessage(hr)]);结尾;MAPI_E_ATTACHMENT_OPEN_FAILURE:开始//无法打开指定的附件.没有发送任何消息.raise Exception.CreateFmt('Error %s 发送电子邮件消息:%s', ['MAPI_E_ATTACHMENT_OPEN_FAILURE', SysErrorMessage(hr)]);结尾;MAPI_E_BAD_RECIPTYPE:开始//收件人类型不是MAPI_TO、MAPI_CC或MAPI_BCC.没有发送任何消息.raise Exception.CreateFmt('Error %s 发送电子邮件消息:%s', ['MAPI_E_BAD_RECIPTYPE', SysErrorMessage(hr)]);结尾;MAPI_E_FAILURE:开始//发生了一个或多个未指定的错误.没有发送任何消息.raise Exception.CreateFmt('Error %s 发送电子邮件消息:%s', ['MAPI_E_FAILURE', SysErrorMessage(hr)]);结尾;MAPI_E_INSUFFICIENT_MEMORY:开始//内存不足,无法继续.没有发送任何消息.raise Exception.CreateFmt('Error %s 发送电子邮件:%s', ['MAPI_E_INSUFFICIENT_MEMORY', SysErrorMessage(hr)]);结尾;MAPI_E_INVALID_RECIPS:开始//一个或多个收件人无效或未解析到任何地址.raise Exception.CreateFmt('Error %s 发送电子邮件消息:%s', ['MAPI_E_INVALID_RECIPS', SysErrorMessage(hr)]);结尾;MAPI_E_LOGIN_FAILURE:开始//没有默认登录,显示登录对话框时用户登录失败.没有发送任何消息.raise Exception.CreateFmt('Error %s 发送电子邮件消息:%s', ['MAPI_E_LOGIN_FAILURE', SysErrorMessage(hr)]);结尾;MAPI_E_TEXT_TOO_LARGE:开始//消息中的文本太大.没有发送任何消息.raise Exception.CreateFmt('Error %s 发送电子邮件:%s', ['MAPI_E_TEXT_TOO_LARGE', SysErrorMessage(hr)]);结尾;MAPI_E_TOO_MANY_FILES:开始//文件附件过多.没有发送任何消息.raise Exception.CreateFmt('Error %s 发送电子邮件:%s', ['MAPI_E_TOO_MANY_FILES', SysErrorMessage(hr)]);结尾;MAPI_E_TOO_MANY_RECIPIENTS:开始//收件人过多.没有发送任何消息.raise Exception.CreateFmt('Error %s 发送电子邮件:%s', ['MAPI_E_TOO_MANY_RECIPIENTS', SysErrorMessage(hr)]);结尾;MAPI_E_UNICODE_NOT_SUPPORTED:开始//指定了MAPI_FORCE_UNICODE标志,不支持Unicode.//注意 此值只能由 MAPISendMailW 返回.raise Exception.CreateFmt('Error %s 发送电子邮件:%s', ['MAPI_E_UNICODE_NOT_SUPPORTED', SysErrorMessage(hr)]);结尾;MAPI_E_UNKNOWN_RECIPIENT:开始//收件人没有出现在地址列表中.没有发送任何消息.raise Exception.CreateFmt('Error %s 发送电子邮件:%s', ['MAPI_E_UNKNOWN_RECIPIENT', SysErrorMessage(hr)]);结尾;MAPI_E_USER_ABORT:开始es := '用户取消了其中一个对话框.没有消息发送.';raise Exception.CreateFmt('Error %s 发送电子邮件消息:%s', ['MAPI_E_USER_ABORT', es]);结尾;别的raise Exception.CreateFmt('Error %d 发送电子邮件消息:%s', [hr, SysErrorMessage(hr)]);结尾;结尾;

<块引用>

注意:任何代码都被发布到公共领域.无需署名.

Given some files (or shell file objects) how do i invoke the .MAPIMail registered shell extension handler with them?


The Question

i have some files on the computer:

  • C:\Users\ian\AppData\Local\Temp\Contoso_Invoice_141174.pdf
  • C:\Users\ian\AppData\Local\Temp\Contoso_Invoice_141173.pdf
  • C:\Users\ian\AppData\Local\Temp\Contoso_Invoice_141171.pdf

That i want to do the programmatic equivalent of dropping them on the .MAPIMail registered handler:

The Sent to folder's Mail recipient option is actually a special registered .MAPIMail extension:

Which is a file type that is registered on the system:

HKEY_CLASSES_ROOT\.mapimail

How do i invoke a drop onto a ephermeral .mapimail file?

Can't you just look in the registry?

Now, i could be a bad developer, and spellunk the registry, the .mapimail entry's default value:

CLSID\{9E56BE60-C50F-11CF-9A2C-00A0C90A90CE}

Extract the clsid {9E56BE60-C50F-11CF-9A2C-00A0C90A90CE}, and confirm that class is registered:

HKEY_CLASSES_ROOT\CLSID\{9E56BE60-C50F-11CF-9A2C-00A0C90A90CE}
    (default) = Desktop Shortcut
    \InProcServer32
        (default) = %SystemRoot%\System32\sendmail.dll

And use CoCreateInstance to create that COM object:

IUnknown unk = CreateComObject("{9E56BE60-C50F-11CF-9A2C-00A0C90A90CE}");

And then i'm in an undocumented, unsupported world, where i don't know what interface i have to QueryInterface for, and what methods to call in what order.

So we're left with shell programming

What i'd like is to likely something involving the shell (pseudo-code):

IShellFolder desktop;
OleCheck(SHGetDesktopFolder(out desktop));

List<pidl> pidls = new List<pidl>();

ULONG chEaten = 0;
ULONG dwAttributes = 0;
PIDL pidl;

foreach (String filename in Files) do
{
    OleCheck(desktop.ParseDisplayName(0, nil, filename, out chEaten, out pidl, ref dwAttributes));

    pidls.Add(pidl);
}

//Get the shell folder of the temp folder
IShellFolder tempShellFolder;
desktop.ParseDisplayName(0, nil, GetTemporaryPath, out chEaten, out pidl, ref dwAttributes));
desktop.BindToObject(pidl, nil, IShellFolder, tempShellFolder);

//i have no idea what i've been doing; just throwing reasonable looking code together
//nobody will actually ever read this

IDontCare context;

tempShellFolder.GetUIObjectOf(0, pidls.Count, pidls, IDontCareAnymore, nil, ref context); 

Except all that code relies on the extistance of a context menu, which i don't have. Nobody says that .MAPIMail has to be in any context Send to menu.

i was asking how to drop files on a .mapimail file.

And my god.

Why not just use MAPI?

Because no MAPI client is installed when you're a 32-bit application running on Windows 64-bit with Office 64-bit installed. So i need to be able to accomplish what the user already can.

解决方案

Although it doesn't answer my question, Raymond pointed out that it's a stupid question. Nobody in their right mind should be trying to send mail to recipients. But i was desperate!

Turns out i'm not completely stuck. While there is a bitness nightmare when dealing with 64-bit Outlook (MAPI provider) from 32-bit applications (or vice versa), there is one out.

If i use just MapiSendMail, and no other MAPI functions, it is safe to cross the 32-bit/64-bit barrier. From Building MAPI Applications on 32-Bit and 64-Bit Platforms:

32-bit MAPI Application and 64-Bit Outlook

32-bit MAPI applications are not supported to run on a computer installed with 64-bit Outlook and 64-bit Windows. The application developer must update and rebuild the application as a 64-bit application for the 64-bit platform. This is because a 32-bit application cannot load a 64-bit Msmapi32.dll file. There are a small number of API changes that application developers must incorporate to build their code successfully for a 64-bit environment. MAPI header files have been updated with these changes to support the 64-bit platform. You can download these header files at Outlook 2010: MAPI Header Files. Developers can use this same set of MAPI header files to build both 32-bit and 64-bit MAPI applications

That makes it sound like all hope is lost. But, there is, on Windows 7:

Exception: MAPISendMail

However, one function call among all Simple MAPI and MAPI elements, MAPISendMail, would succeed in a Windows-32-bit-on-Windows-64-bit (WOW64) or Windows-64-bit-on-Windows-32-bit (WOW32) scenario and would not result in the above alert. This WOW64 scenario only applies to Windows 7. Figure 2 shows a WOW64 scenario in which a 32-bit MAPI application calls MAPISendMail on a computer installed with 64-bit Windows 7. In this scenario, the MAPI library makes a COM call to launch a 64-bit Fixmapi application. The Fixmapi application implicitly links to the MAPI library, which routes the function call to the Windows MAPI stub, which in turn forwards the call to the Outlook MAPI stub, enabling the MAPISendMail function call to succeed.

So, as a Delphi Jedi user, their Simple Send E-mail functions will fail (as they use too much of MAPI). So i had to create my own:

procedure MapiSimpleSendMail(slFiles: TStrings; ToEmailAddress: string=''; ToName: string='');
var
    mapiMessage: TMapiMessage;
    flags: LongWord;
//  senderName: AnsiString;
//  senderEmailAddress: AnsiString;
    emailSubject: AnsiString;
    emailBody: AnsiString;
//  sender: TMapiRecipDesc;
    recipients: packed array of TMapiRecipDesc;
    attachments: packed array of TMapiFileDesc;
    i: Integer;
    hr: Cardinal;
    es: string;
const
    MAPI_E_UNICODE_NOT_SUPPORTED = 27; //Windows 8. The MAPI_FORCE_UNICODE flag is specified and Unicode is not supported.
begin
    ZeroMemory(@mapiMessage, SizeOf(mapiMessage));

{   senderName := '';
    senderEmailAddress := '';

    ZeroMemory(@sender, sizeof(sender));
    sender.ulRecipClass := MAPI_ORIG; //MAPI_TO, MAPI_CC, MAPI_BCC, MAPI_ORIG
    sender.lpszName := PAnsiChar(senderName);
    sender.lpszAddress := PAnsiChar(senderEmailAddress);}
    mapiMessage.lpOriginator := nil; //PMapiRecipDesc; { Originator descriptor                  }

    if ToEmailAddress <> '' then
    begin
        SetLength(recipients, 1);
        recipients[0].ulRecipClass := MAPI_TO;
        recipients[0].lpszName := LPSTR(ToName);
        recipients[0].lpszAddress := LPSTR(ToEmailAddress);

        mapiMessage.lpRecips := @recipients[0]; //A value of NULL means that there are no recipients. Additionally, when this member is NULL, the nRecipCount member must be zero.
        mapiMessage.nRecipCount := 1;
    end
    else
    begin
        mapiMessage.lpRecips := nil; //A value of NULL means that there are no recipients. Additionally, when this member is NULL, the nRecipCount member must be zero.
        mapiMessage.nRecipCount := 0;
    end;

    mapiMessage.lpszMessageType := nil;

    if slFiles.Count > 0 then
    begin
        emailSubject := 'Emailing: ';
        emailBody :=
                '          '+#13#10+ //Yes, the shell really does create a blank mail with a leading line of ten spaces
                'Your message is ready to be sent with the following file or link attachments:'+#13#10;


    SetLength(attachments, slFiles.Count);
        for i := 0 to slFiles.Count-1 do
        begin
            attachments[i].ulReserved := 0; // Cardinal;        { Reserved for future use (must be 0)     }
            attachments[i].flFlags := 0; // Cardinal;           { Flags                                   }
            attachments[i].nPosition := $FFFFFFFF; //Cardinal;         { character in text to be replaced by attachment }
            attachments[i].lpszPathName := PAnsiChar(slFiles[i]);    { Full path name of attachment file       }
            attachments[i].lpszFileName := nil; // LPSTR;         { Original file name (optional)           }
            attachments[i].lpFileType := nil; // Pointer;         { Attachment file type (can be lpMapiFileTagExt) }

            if i > 0 then
                emailSubject := emailSubject+', ';
            emailSubject := emailSubject+ExtractFileName(slFiles[i]);
            emailBody := emailBody+#13#10+
                    ExtractFileName(slFiles[i]);
        end;

        emailBody := emailBody+#13#10+
                #13#10+
                #13#10+
                'Note: To protect against computer viruses, e-mail programs may prevent sending or receiving certain types of file attachments.  Check your e-mail security settings to determine how attachments are handled.';


        mapiMessage.lpFiles := @attachments[0];
        mapiMessage.nFileCount := slFiles.Count;
    end
    else
    begin
        emailSubject := '';
        emailBody := '';

        mapiMessage.lpFiles := nil;
        mapiMessage.nFileCount := 0;
    end;

    {
        Subject
        Emailing: 4388_888871544_MVM_10.tmp, amt3.log, swtag.log, wct845C.tmp, ~vs1830.sql

        Body
                  <-- ten spaces
        Your message is ready to be sent with the following file or link attachments:

        4388_888871544_MVM_10.tmp
        amt3.log
        swtag.log
        wct845C.tmp
        ~vs1830.sql


        Note: To protect against computer viruses, e-mail programs may prevent sending or receiving certain types of file attachments.  Check your e-mail security settings to determine how attachments are handled.
    }
    mapiMessage.lpszSubject := PAnsiChar(emailSubject);
    mapiMessage.lpszNoteText := PAnsiChar(emailBody);


    flags := MAPI_DIALOG;

    hr := Mapi.MapiSendMail(0, 0, mapiMessage, flags, 0);
    case hr of
    SUCCESS_SUCCESS: {nop}; //The call succeeded and the message was sent.
    MAPI_E_AMBIGUOUS_RECIPIENT:
        begin
            //es := 'A recipient matched more than one of the recipient descriptor structures and MAPI_DIALOG was not set. No message was sent.';
            raise Exception.CreateFmt('Error %s sending e-mail message: %s', ['MAPI_E_AMBIGUOUS_RECIPIENT', SysErrorMessage(hr)]);
        end;
    MAPI_E_ATTACHMENT_NOT_FOUND:
        begin
            //The specified attachment was not found. No message was sent.
            raise Exception.CreateFmt('Error %s sending e-mail message: %s', ['MAPI_E_ATTACHMENT_NOT_FOUND', SysErrorMessage(hr)]);
        end;
    MAPI_E_ATTACHMENT_OPEN_FAILURE:
        begin
            //The specified attachment could not be opened. No message was sent.
            raise Exception.CreateFmt('Error %s sending e-mail message: %s', ['MAPI_E_ATTACHMENT_OPEN_FAILURE', SysErrorMessage(hr)]);
        end;
    MAPI_E_BAD_RECIPTYPE:
        begin
            //The type of a recipient was not MAPI_TO, MAPI_CC, or MAPI_BCC. No message was sent.
            raise Exception.CreateFmt('Error %s sending e-mail message: %s', ['MAPI_E_BAD_RECIPTYPE', SysErrorMessage(hr)]);
        end;
    MAPI_E_FAILURE:
        begin
            //One or more unspecified errors occurred. No message was sent.
            raise Exception.CreateFmt('Error %s sending e-mail message: %s', ['MAPI_E_FAILURE', SysErrorMessage(hr)]);
        end;
    MAPI_E_INSUFFICIENT_MEMORY:
        begin
            //There was insufficient memory to proceed. No message was sent.
            raise Exception.CreateFmt('Error %s sending e-mail message: %s', ['MAPI_E_INSUFFICIENT_MEMORY', SysErrorMessage(hr)]);
        end;
    MAPI_E_INVALID_RECIPS:
        begin
            //One or more recipients were invalid or did not resolve to any address.
            raise Exception.CreateFmt('Error %s sending e-mail message: %s', ['MAPI_E_INVALID_RECIPS', SysErrorMessage(hr)]);
        end;
    MAPI_E_LOGIN_FAILURE:
        begin
            //There was no default logon, and the user failed to log on successfully when the logon dialog box was displayed. No message was sent.
            raise Exception.CreateFmt('Error %s sending e-mail message: %s', ['MAPI_E_LOGIN_FAILURE', SysErrorMessage(hr)]);
        end;
    MAPI_E_TEXT_TOO_LARGE:
        begin
            //The text in the message was too large. No message was sent.
            raise Exception.CreateFmt('Error %s sending e-mail message: %s', ['MAPI_E_TEXT_TOO_LARGE', SysErrorMessage(hr)]);
        end;
    MAPI_E_TOO_MANY_FILES:
        begin
            //There were too many file attachments. No message was sent.
            raise Exception.CreateFmt('Error %s sending e-mail message: %s', ['MAPI_E_TOO_MANY_FILES', SysErrorMessage(hr)]);
        end;
    MAPI_E_TOO_MANY_RECIPIENTS:
        begin
            //There were too many recipients. No message was sent.
            raise Exception.CreateFmt('Error %s sending e-mail message: %s', ['MAPI_E_TOO_MANY_RECIPIENTS', SysErrorMessage(hr)]);
        end;
    MAPI_E_UNICODE_NOT_SUPPORTED:
        begin
            //The MAPI_FORCE_UNICODE flag is specified and Unicode is not supported.
            //Note  This value can be returned by MAPISendMailW only.
            raise Exception.CreateFmt('Error %s sending e-mail message: %s', ['MAPI_E_UNICODE_NOT_SUPPORTED', SysErrorMessage(hr)]);
        end;
    MAPI_E_UNKNOWN_RECIPIENT:
        begin
            //A recipient did not appear in the address list. No message was sent.
            raise Exception.CreateFmt('Error %s sending e-mail message: %s', ['MAPI_E_UNKNOWN_RECIPIENT', SysErrorMessage(hr)]);
        end;
    MAPI_E_USER_ABORT:
        begin
            es := 'The user canceled one of the dialog boxes. No message was sent.';
            raise Exception.CreateFmt('Error %s sending e-mail message: %s', ['MAPI_E_USER_ABORT', es]);
        end;
    else
        raise Exception.CreateFmt('Error %d sending e-mail message: %s', [hr, SysErrorMessage(hr)]);
    end;
end;

Note: Any code is released into the public domain. No attribution required.

这篇关于如何将文件拖放到 .MAPIMail的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆