为什么 SendMailMAPI 将文件附件重命名为较短的附件?

发布于 2024-08-30 00:07:46 字数 2681 浏览 7 评论 0原文

我在 Eudora 中使用以下电子邮件功能。由于某种原因,附件文件名被重命名为其他名称。如何确保附件文件名保持不变?

function SendMailMAPI(const Subject, Body, FileName, SenderName, SenderEMail, 
                  RecepientName, RecepientEMail: String) : 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 := PChar(Subject) 
    end; 
    if (Body<>'') then 
    begin 
      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; 
      lpOriginator := @lpSender; 
    end; 
    if (RecepientEMail<>'') then 
    begin 
      lpRecepient.ulRecipClass := MAPI_TO; 
      if (RecepientName='') then 
      begin 
        lpRecepient.lpszName := PChar(RecepientEMail) 
      end 
      else 
      begin 
        lpRecepient.lpszName := PChar(RecepientName) 
      end; 
      lpRecepient.lpszAddress := PChar('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 := PChar(FileName); 
      nFileCount := 1; 
      lpFiles := @FileAttach; 
    end; 
  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 
    MessageDlg('Error sending mail ('+IntToStr(Result)+').', mtError, [mbOk], 
               0) 
  end; 

I use the following emailing function with Eudora. For some reason the attachment file name is renamed to be something else. How can I make sure the attachment file name remains intact?

function SendMailMAPI(const Subject, Body, FileName, SenderName, SenderEMail, 
                  RecepientName, RecepientEMail: String) : 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 := PChar(Subject) 
    end; 
    if (Body<>'') then 
    begin 
      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; 
      lpOriginator := @lpSender; 
    end; 
    if (RecepientEMail<>'') then 
    begin 
      lpRecepient.ulRecipClass := MAPI_TO; 
      if (RecepientName='') then 
      begin 
        lpRecepient.lpszName := PChar(RecepientEMail) 
      end 
      else 
      begin 
        lpRecepient.lpszName := PChar(RecepientName) 
      end; 
      lpRecepient.lpszAddress := PChar('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 := PChar(FileName); 
      nFileCount := 1; 
      lpFiles := @FileAttach; 
    end; 
  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 
    MessageDlg('Error sending mail ('+IntToStr(Result)+').', mtError, [mbOk], 
               0) 
  end; 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彡翼 2024-09-06 00:07:46

您必须将 FileAttach.lpszFileName 设置为您希望收件人看到的名称。如果您不这样做,"C:\Document And Settings\MyUser\Local Settings\Temp\Hello.pdf" 之类的附件将类似于 "C__DOCUME~1_MyUser_LOCALS~1_Temp_Hello.pdf ” 给收件人(每个电子邮件客户端可能有所不同)。

因此,将 FileAttach.lpszPathName 设置为仅包含文件名:

begin 
  FillChar(FileAttach, SizeOf(FileAttach), 0); 
  FileAttach.nPosition := Cardinal($FFFFFFFF); 
  FileAttach.lpszPathName := PChar(FileName); 
  FileAttach.lpszFileName := PChar(ExtractFileName(FileName)); //add this
  nFileCount := 1; 
  lpFiles := @FileAttach; 
end;

收件人现在将看到名称为“Hello.pdf”的附件,而不是“C__DOCUME~1_MyUser_LOCALS~1_Temp_Hello.pdf”。

You have to set FileAttach.lpszFileName to the name you want your recipient to see. If you don't do that an attachment like "C:\Document And Settings\MyUser\Local Settings\Temp\Hello.pdf" will look like "C__DOCUME~1_MyUser_LOCALS~1_Temp_Hello.pdf" to the recipient (this is probably different per e-mailclient ).

So set FileAttach.lpszPathName to contain only the filename:

begin 
  FillChar(FileAttach, SizeOf(FileAttach), 0); 
  FileAttach.nPosition := Cardinal($FFFFFFFF); 
  FileAttach.lpszPathName := PChar(FileName); 
  FileAttach.lpszFileName := PChar(ExtractFileName(FileName)); //add this
  nFileCount := 1; 
  lpFiles := @FileAttach; 
end;

The recipient will now see an attachment with the name "Hello.pdf" instead of "C__DOCUME~1_MyUser_LOCALS~1_Temp_Hello.pdf".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文