gpt4 book ai didi

delphi - 如何将带有附件的 MAPI 电子邮件发送给传真收件人?

转载 作者:行者123 更新时间:2023-12-02 09:25:50 30 4
gpt4 key购买 nike

我正在使用this method从 Delphi 应用程序内部发送带有 PDF 附件的 MAPI 电子邮件。

它会打开一个 MS Outlook“新消息”窗口,其中已附加 pdf 文档和一个空白收件人。

如果您输入普通的电子邮件联系方式,那么一切都会顺利进行。

但是,如果您选择传真收件人,它会出现在我的“已发送邮件”文件夹中,但传送会失败(没有错误,没有 MS Outlook“传送失败”消息,并且不会传送消息)。

“传真收件人”是在 MS Outlook 中设置的,只有一个传真号码。没有电子邮件或任何东西。我们使用faxcore server将这些“传真”路由到 Outlook 收件箱。

如果您look at this image ,我为此联系人填写的唯一字段是标有“商务传真”的字段。

如果我手动(即在我的应用程序之外)创建标准 MS Outlook 电子邮件并选择完全相同的传真收件人,并手动附加完全相同的 PDF,那么一切都会顺利进行。

因此,使用 MAPI 发送传真号码似乎会导致失败。 This post sounds similar, except they get a "message undeliverable" error and I don't.

有人可以给我一些建议吗?

谢谢

更新:如果我使用 MAPI 创建电子邮件,然后手动删除附件,那么它确实可以工作。因此,在 Outlook 中,我可以通过电子邮件将附件发送给传真收件人,但使用 MAPI 会失败。

完整源代码如下:

unit Main;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
function SendEMailUsingMAPI(const Subject, Body, FileName, SenderName,
SenderEMail, RecipientName, RecipientEMail: string): integer;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

uses
Mapi;

procedure TForm1.Button1Click(Sender: TObject);
begin
//this will bring up an MS Outlook dialog.
//inside that dialog, if i choose a normal email recipient, it works.
// if i choose a fax recipient, it fails silently.
//if i create the email from w/in outlook, it can go to *either* with success.

SendEmailUsingMAPI(
'Subject', //subject of email
'Body', //body of email text
'c:\my_doc.pdf', //attachment file name
'My name', //sender email name
'myemail@mydomain.com', //sender email address
'', //recipient email name
''); //recipient email address
end;


function TForm1.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
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(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(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
MessageDlg('Error sending mail ('+IntToStr(Result)+').',mtError,[mbOK],0);
end;
end;

end.

最佳答案

好的,您的更新指向附件,所以我将提出另一个猜测:尝试将附件的文件类型明确设置为“application/pdf”(您当前的代码未设置 lpFileType 字段)。传真处理可能取决于此。您可以将 MapiFileTagExt 的编码部分(lpFileType 指向的类型)留空,只需 FillChar 记录并设置 cbTag 和 lpTag 字段。

如果你需要代码(mapi 结构有时可能有点令人眼花缭乱),就大喊吧,但我需要一些时间才能找到时间来输入它。无论如何,再说一次,我只是猜测。我的家庭环境中没有传真设置,否则我会做一些适当的测试。

编辑

说明下面的代码。但是,此后我检查了 Outlook Spy,无论使用哪种方法,还是手动附加文件时,PR_ATTACH_MIME_TAG 属性似乎都是在发送的项目上设置的,而仅在生成的传入消息上设置。

  FillChar(FileAttach,SizeOf(FileAttach),0);
FileAttach.nPosition := Cardinal($FFFFFFFF);
FileAttach.lpszPathName := PChar(FileName);
//
MimeType := 'application/pdf';
//
FileType.ulReserved := 0;
FileType.cbTag := Length( MimeType );
FileType.lpTag := PByte(MimeType);
FileType.cbEncoding := 0;
FileType.lpEncoding := nil;
//
FileAttach.lpFileType := @FileType;
Message.nFileCount := 1;
Message.lpFiles := @FileAttach;

(代码格式化程序并不是特别有用)。

关于delphi - 如何将带有附件的 MAPI 电子邮件发送给传真收件人?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1234623/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com