1、你可以调试一下,但是需要注意的是,代码是针对Office里面的那个OutLook,而不是Outlook Express
对outlook讲述比较详细的就是这个帖子里面的东西了
http://www.delphibbs.com/delphibbs/dispq.asp?LID=602136
还有
http://www.delphibbs.com/delphibbs/dispq.asp?LID=2103554
标题: 调用默认的EMAIL客户端发送邮件的问题,各位受累
另外还有调用默认邮件程序发送邮件的代码,首先一定要确保这个默认程序里面有账号,然后就可以发送了
------------------------转自网络
unit Main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, mapi;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$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'] := 'chenybin@.com';
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'] := 'c:/a.htm'; //附件路径要存在
SendEMail(Application.Handle, Mail);
Mail.Free;
end;
end.