outlook发送对话框没有显示

时间:2015-12-14 10:20:58

标签: delphi outlook mapi

我有一个delphi 6应用程序,它使用mapi打开outlook发送对话框 附件。 这适用于我的PC和其他客户端PC。

我现在有2个客户端,其中发送对话框没有打开。我甚至得不到 错误信息。客户拥有W7 PC和outlook 2013。 我尝试过Fixmapi,但这没有用。

Outlook工作正常,通过浏览器发送对话工作正常。

1 个答案:

答案 0 :(得分:1)

我刚试过MAPI,它对我有用,有雷鸟和Outlook 2013。

我确实得到了一个FIXMAPI对话框,然后我得到了新的Outlook电子邮件窗口,与以往一样。

如果您只在特定计算机上遇到问题,那么这不是编程问题,而是一个Windows问题。请务必使用“控制面板”查看您选择的默认程序,包括默认的MAPI邮件程序。

program MapiSample;

uses
  {Vcl.}Forms,
  Windows,
  SysUtils,
  {Vcl.}Dialogs,
  {WinApi.}MAPI;

type
  LPSTR = PAnsiChar;
  PSTR = PChar;

function SendMailMAPI(const Subject, Body, FileName, SenderName, SenderEMail,
                  RecepientName, RecepientEMail: AnsiString) : Integer;
var
  message: TMapiMessage;
  lpSender,
  lpRecepient: TMapiRecipDesc;
  FileAttach: TMapiFileDesc;
  SM: TFNMapiSendMail;
  MAPIModule: HModule;
begin
  FillChar(message, SizeOf(message), 0);
  with message do
  begin
    if (Subject<>'') then
    begin
      lpszSubject := LPSTR(Subject)
    end;
    if (Body<>'') then
    begin
      lpszNoteText := LPSTR(Body)
    end;
    if (SenderEMail<>'') then
    begin
      lpSender.ulRecipClass := MAPI_ORIG;
      if (SenderName='') then
      begin
        lpSender.lpszName := LPSTR(SenderEMail)
      end
      else
      begin
        lpSender.lpszName := LPSTR(SenderName)
      end;
      lpSender.lpszAddress := LPSTR('SMTP:'+SenderEMail);
      lpSender.ulReserved := 0;
      lpSender.ulEIDSize := 0;
      lpSender.lpEntryID := nil;
      lpOriginator := @lpSender;
    end;
    if (RecepientEMail<>'') then
    begin
      lpRecepient.ulRecipClass := MAPI_TO;
      if (RecepientName='') then
      begin
        lpRecepient.lpszName := LPSTR(RecepientEMail)
      end
      else
      begin
        lpRecepient.lpszName := LPSTR(RecepientName)
      end;
      lpRecepient.lpszAddress := LPSTR('SMTP:'+RecepientEMail);
      lpRecepient.ulReserved := 0;
      lpRecepient.ulEIDSize := 0;
      lpRecepient.lpEntryID := nil;
      nRecipCount := 1;
      lpRecips := @lpRecepient;
    end
    else
    begin
      lpRecips := nil
    end;
    if (FileName='') then
    begin
      nFileCount := 0;
      lpFiles := nil;
    end
    else
    begin
      FillChar(FileAttach, SizeOf(FileAttach), 0);
      FileAttach.nPosition := Cardinal($FFFFFFFF);
      FileAttach.lpszPathName := LPSTR(FileName);
      nFileCount := 1;
      lpFiles := @FileAttach;
    end;
  end;
  MAPIModule := LoadLibrary(PSTR(MAPIDLL));
  if MAPIModule=0 then
  begin
    Result := -1
  end
  else
  begin
    try
      @SM := GetProcAddress(MAPIModule, 'MAPISendMail');
      if @SM<>nil then
      begin
        Result := SM(0, Application.Handle, message, MAPI_DIALOG or
                     MAPI_LOGON_UI, 0);
      end
      else
      begin
        Result := 1
      end;

    finally
      FreeLibrary(MAPIModule);
    end;
  end;
  if Result<>0 then
  begin
    MessageDlg('Error sending mail ('+IntToStr(Result)+').', mtError, [mbOk],
               0)
  end;
end;

begin
    SendMailMapi('test','test','','My Name', 'sender@sender.com', 'Your Name', 'receiver@something.com');

end.