【问题标题】:Can TNEF be avoided using MAPI?可以使用 MAPI 避免 TNEF 吗?
【发布时间】:2018-03-02 00:03:38
【问题描述】:

我正在使用 this code 使用 Delphi 通过 MAPI 发送电子邮件。

一些使用 Microsoft 邮件软件的用户报告说,收件人收到带有 WinMail.dat 附件的电子邮件。我知道这是 Microsoft Exchange/Outlook 的问题,可以通过禁用 RTF/TNEF 来纠正。 (我不确定,因为我不使用 Microsoft 邮件软件)。

我的问题是,我是否可以通过 MAPI 告诉邮件软件不要使用 TNEF。

function SendEMailUsingMAPI(const Subject, Body, FileName, SenderName, SenderEMail, RecipientName, RecipientEMail: string): Integer;
var
  Message: TMapiMessage;
  lpSender, lpRecipient: TMapiRecipDesc;
  FileAttach: TMapiFileDesc;
  SM: TFNMapiSendMail;
  MAPIModule: HModule;
  FileType: TMapiFileTagExt;
begin
  // Source: http://www.stackoverflow.com/questions/1234623/how-to-send-a-mapi-email-with-an-attachment-to-a-fax-recipient
  // Modified

  FillChar(Message,SizeOf(Message),0);

  if (Subject <> '') then begin
    Message.lpszSubject := PChar(Subject);
  end;

  if (Body <> '') then begin
    Message.lpszNoteText := PChar(Body);
  end;

  if (SenderEmail <> '') then
  begin
    lpSender.ulRecipClass := MAPI_ORIG;
    if (SenderName = '') then begin
      lpSender.lpszName := PChar(SenderEMail);
    end
    else begin
      lpSender.lpszName := PChar(SenderName);
    end;
    lpSender.lpszAddress := PChar('smtp:'+SenderEmail);
    lpSender.ulReserved := 0;
    lpSender.ulEIDSize := 0;
    lpSender.lpEntryID := nil;
    Message.lpOriginator := @lpSender;
  end;

  if (RecipientEmail <> '') then
  begin
    lpRecipient.ulRecipClass := MAPI_TO;
    if (RecipientName = '') then begin
      lpRecipient.lpszName := PChar(RecipientEMail);
    end
    else begin
      lpRecipient.lpszName := PChar(RecipientName);
    end;
    lpRecipient.lpszAddress := PChar('smtp:'+RecipientEmail);
    lpRecipient.ulReserved := 0;
    lpRecipient.ulEIDSize := 0;
    lpRecipient.lpEntryID := nil;
    Message.nRecipCount := 1;
    Message.lpRecips := @lpRecipient;
  end
  else begin
    Message.lpRecips := nil;
  end;

  if (FileName = '') then begin
    Message.nFileCount := 0;
    Message.lpFiles := nil;
  end
  else begin
    FillChar(FileAttach,SizeOf(FileAttach),0);
    FileAttach.nPosition := Cardinal($FFFFFFFF);
    FileAttach.lpszPathName := PChar(FileName);

    FileType.ulReserved := 0;
    FileType.cbEncoding := 0;
    FileType.cbTag := 0;
    FileType.lpTag := nil;
    FileType.lpEncoding := nil;

    FileAttach.lpFileType := @FileType;
    Message.nFileCount := 1;
    Message.lpFiles := @FileAttach;
  end;

  MAPIModule := LoadLibrary(PChar(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
    raise Exception.CreateFmt('Error sending eMail (%d)', [Result]);
  end;
end;

【问题讨论】:

    标签: delphi exchange-server mapi


    【解决方案1】:

    不在简单 MAPI 中。如果您使用的是 Outlook 对象模型或扩展 MAPI,则可以在发送邮件之前在邮件上设置一个特殊的 MAPI 属性以禁用 TNEF 格式。

    【讨论】:

    • 感谢您的提示。我将寻找有关扩展 MAPI 的更多信息。顺便问一下,你知道 Outlook 什么时候选择 TNEF,什么时候不选择?奇怪的是,最终用户总是发送带有 PDF 的电子邮件,而他们从来都不是 TNEF。但是,如果他们使用我的程序创建电子邮件(带有 PDF 附件),则电子邮件将变为 TNEF。
    猜你喜欢
    • 1970-01-01
    • 2012-12-28
    • 1970-01-01
    • 1970-01-01
    • 2019-01-10
    • 2011-07-05
    • 1970-01-01
    • 1970-01-01
    • 2011-04-06
    相关资源
    最近更新 更多