Delphi 使用MAPI可以避免TNEF吗?

Delphi 使用MAPI可以避免TNEF吗?,delphi,exchange-server,mapi,Delphi,Exchange Server,Mapi,我使用Delphi通过MAPI发送电子邮件 一些使用Microsoft邮件软件的用户报告说,收件人收到带有附件的电子邮件WinMail.dat。我知道这是Microsoft Exchange/Outlook的一个问题,可以通过禁用RTF/TNEF来纠正。(我不确定,因为我不使用Microsoft邮件软件) 我的问题是,我是否可以告诉邮件软件不要使用MAPI使用TNEF function SendEMailUsingMAPI(const Subject, Body, FileName, Sende

我使用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;
函数SendEMailUsingMAPI(常量主题、正文、文件名、SenderName、SenderEMail、RecipientName、RecipientEMail:string):整数;
变量
消息:TMapiMessage;
lpSender,lpRecipient:TMapiRecipDesc;
FileAttach:TMapiFileDesc;
SM:TFNMapiSendMail;
MAPIModule:HModule;
文件类型:TMapiFileTagExt;
开始
//资料来源:http://www.stackoverflow.com/questions/1234623/how-to-send-a-mapi-email-with-an-attachment-to-a-fax-recipient
//修改
FillChar(消息,SizeOf(消息),0);
如果是(主题“”),则开始
Message.lpszSubject:=PChar(Subject);
结束;
如果是(正文“”),则开始
Message.lpszNoteText:=PChar(正文);
结束;
如果(SenderEmail“”),则
开始
lpSender.ulRecipClass:=MAPI_ORIG;
如果(SenderName=''),则开始
lpSender.lpszName:=PChar(SenderEMail);
结束
否则开始
lpSender.lpszName:=PChar(SenderName);
结束;
lpSender.lpszAddress:=PChar('smtp:'+SenderEmail);
lpSender.ulReserved:=0;
lpSender.ulEIDSize:=0;
lpSender.lpEntryID:=nil;
Message.lpOriginator:=@lpSender;
结束;
如果(收件人电子邮件“”),则
开始
lpRecipient.ulRecipClass:=MAPI_TO;
如果(RecipientName=''),则开始
lpRecipient.lpszName:=PChar(RecipientEMail);
结束
否则开始
lpRecipient.lpszName:=PChar(RecipientName);
结束;
lpRecipient.lpszAddress:=PChar('smtp:'+RecipientEmail);
lpRecipient.ulReserved:=0;
lpRecipient.ulEIDSize:=0;
lpRecipient.lpEntryID:=nil;
Message.nRecipCount:=1;
Message.lpRecips:=@lpRecipient;
结束
否则开始
Message.lpRecips:=nil;
结束;
如果(文件名=“”),则开始
Message.nFileCount:=0;
Message.lpFiles:=nil;
结束
否则开始
FillChar(FileAttach,SizeOf(FileAttach),0);
FileAttach.nPosition:=基数($ffffffffff);
FileAttach.lpszPathName:=PChar(文件名);
FileType.ulReserved:=0;
FileType.cbEncoding:=0;
FileType.cbTag:=0;
FileType.lpTag:=nil;
FileType.lpEncoding:=nil;
FileAttach.lpFileType:=@FileType;
Message.nFileCount:=1;
Message.lpFiles:=@FileAttach;
结束;
MAPIModule:=加载库(PChar(MAPIDLL));
如果MAPIModule=0,则开始
结果:=-1;
结束
否则开始
尝试
@SM:=GetProcAddress(MAPIModule,'MAPISendMail');
如果@SM nil,则开始
结果:=SM(0,Application.Handle,Message,
MAPI_对话框或MAPI_登录界面,0);
结束
否则开始
结果:=1;
结束;
最后
免费图书馆(MAPI模块);
结束;
结束;
如果结果为0,则开始
引发异常。CreateFmt('Error sending eMail(%d)'[Result]);
结束;
结束;

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

谢谢你的提示。我将查找有关扩展MAPI的更多信息。顺便问一下,您知道Outlook何时选择TNEF,何时不选择TNEF吗?奇怪的是,最终用户总是发送带有PDF的电子邮件,而这些电子邮件从来都不是TNEF。但是,如果他们使用我的程序创建电子邮件(带有PDF附件),电子邮件就会变成TNEF'ed。