顷囊而出,出300分!调用outlook express,能添加附件. 类似快捷菜单zip and E-Mail aaa.zip(300分)

  • 主题发起人 主题发起人 cowbird
  • 开始时间 开始时间
C

cowbird

Unregistered / Unconfirmed
GUEST, unregistred user!
此问题在大富翁中没有解决.
顷囊而出,出300分!调用outlook express,能添加附件. 类似快捷菜单zip and E-Mail aaa.zip.
 
来自:terry_lzs
测试过的,可以用,你在form上放一个button
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses mapi;
{$R *.DFM}
FUNCTION SendEMail(Handle : THandle; Mail : TStrings):Cardinal;
TYPE
TAttachAccessArray = ARRAY [0..0] OF TMapiFileDesc;
PAttachAccessArray = ^TAttachAccessArray;
VAR
MapiMessage : TMapiMessage;
Receip : TMapiRecipDesc;
Attachments : PAttachAccessArray;
AttachCount : INTEGER;
iCount : INTEGER;
FileName : STRING;
BEGIN
fillChar(MapiMessage, SizeOf(MapiMessage), #0);
Attachments := NIL;
fillChar(Receip,SizeOf(Receip), #0);
IF Mail.Values['to'] <> ''
THEN
BEGIN
Receip.ulReserved := 0;
Receip.ulRecipClass := MAPI_TO;
Receip.lpszName := StrNew(PChar(Mail.Values['to']));
Receip.lpszAddress := StrNew(PChar('SMTP:' + Mail.Values['to']));
Receip.ulEIDSize := 0;
MapiMessage.nRecipCount := 1;
MapiMessage.lpRecips := @Receip;
END;
AttachCount := 0;
FOR iCount := 0 TO MaxInt
DO
BEGIN
IF Mail.Values['attachment' + IntToStr(iCount)] = ''
THEN
BREAK;
AttachCount := AttachCount + 1;
END;
IF AttachCount > 0
THEN
BEGIN
GetMem(Attachments,SizeOf(TMapiFileDesc) * AttachCount);
FOR iCount := 0 TO (AttachCount - 1)
DO
BEGIN
FileName := Mail.Values['attachment' + IntToStr(iCount)];
Attachments[iCount].ulReserved := 0;
Attachments[iCount].flFlags := 0;
Attachments[iCount].nPosition := ULONG($FFFFFFFF);
Attachments[iCount].lpszPathName := StrNew(PChar(FileName));
Attachments[iCount].lpszFileName := StrNew(PChar(ExtractFileName(FileName)));
Attachments[iCount].lpFileType := NIL;
END;
MapiMessage.nFileCount := AttachCount;
MapiMessage.lpFiles := @Attachments^;
END;

IF Mail.Values['subject'] <> ''
THEN
MapiMessage.lpszSubject := StrNew(PChar(Mail.Values['subject']));
IF Mail.Values['body'] <> ''
THEN
MapiMessage.lpszNoteText := StrNew(PChar(Mail.Values['body']));

Result := MapiSendMail(0, Handle, MapiMessage,MAPI_DIALOG*Ord(Handle <> 0) OR MAPI_LOGON_UI OR MAPI_NEW_SESSION, 0);

FOR iCount := 0 TO (AttachCount - 1)
DO
BEGIN
strDispose(Attachments[iCount].lpszPathName);
strDispose(Attachments[iCount].lpszFileName);
END;

IF assigned(MapiMessage.lpszSubject)
THEN
strDispose(MapiMessage.lpszSubject);
IF assigned(MapiMessage.lpszNoteText)
THEN
strDispose(MapiMessage.lpszNoteText);
IF assigned(Receip.lpszAddress)
THEN
strDispose(Receip.lpszAddress);
IF assigned(Receip.lpszName)
THEN
strDispose(Receip.lpszName);
END;


procedure TForm1.Button1Click(Sender: TObject);
VAR
mail : TStringList ;
BEGIN
mail := TStringList.Create;
mail.values['to'] := 'delphi2000@8848.net';
mail.values['subject'] := 'A subject';
mail.values['body'] := 'Some body text (line 1)';
mail.values['body'] := 'Some more body text (line 2)';
mail.values['attachment0'] := 'f:/a.txt';//附件路径要存在
sendEMail(Application.Handle, mail);
mail.Free;
end;

end.

 
帮你顶(我在偷笑,300分这次我最少也有几十分吧。呵呵呵)
 
我执行了,却不能看见界面,我希望是类似zip and E-mail a.zip一样,跳出outlook express界面停在那里.而其中含有附件
 
function TMyObject.EmailSend(EmailSubject:string;EmailSite:string;EmailAttachment:string):boolean;
var
MyOutLook:variant;
Item:variant;
FilePathandName:string;
begin
try
MyOutlook := GetActiveOleObject('Outlook.Application');
except
MyOutLook:=CreateOleObject('Outlook.Application');
end;

item:=MyOutlook.CreateItem(0);
item.recipients.add(EmailSite);

item.subject:=EmailSubject;
// item.body:='hello';

item.Attachments.add('c:/' + EmailAttachment,1,1,EmailAttachment);
item.display(1);
end;
 
我试过可以调用outlook express了,
非常感谢samboy111,todayisthursday

请问如何默认的调用formail呢?
 
怎么只能给一个人发,可以多人收件人是多人
加入抄送。
 
var
MyOutLook:variant;
Item:variant;
FilePathandName:string;
begin
try
MyOutlook := GetActiveOleObject('Outlook.Application');
except
MyOutLook:=CreateOleObject('Outlook.Application');
end;

item:=MyOutlook.CreateItem(0);
item.recipients.add(EmailSite);

item.subject:=EmailSubject;
// item.body:='hello';

item.Attachments.add('c:/' + EmailAttachment,1,1,EmailAttachment);
item.display(1);
end;
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部