请教各位高手一个自动发邮件的问题 ( 积分: 200 )

  • 主题发起人 主题发起人 medicineman
  • 开始时间 开始时间
M

medicineman

Unregistered / Unconfirmed
GUEST, unregistred user!
能否提供一段delphi代码,可以实现将某个目录的文件自动打包(调用winzip,winrar也可)并定时发送?邮件系统为outlook。
着急,小弟拜谢!
 
能否提供一段delphi代码,可以实现将某个目录的文件自动打包(调用winzip,winrar也可)并定时发送?邮件系统为outlook。
着急,小弟拜谢!
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1419558
标题是: delphi中调用OUTLOOK发送邮件(带附件)

------------------------转自网络
uses
ComObj;
procedure TForm1.Button1Click(Sender: TObject);
var
Outlook : variant;
Item : variant;
xlsFileName:String;
begin
Try
Outlook := CreateOLEObject('Outlook.Application');
try
Item:=Outlook.CreateItem(0);
xlsFileName:=ExtractFilePath(Application.EXEName)+'project1.exe';
Item.Attachments.Add(xlsFileName,1,1,'project1.exe');
Item.Display(1);
Finally
Update;
Screen.Cursor:=crHourGlass;
Outlook.Quit;
Screen.Cursor:=crDefault;
end;
Except
Showmessage('错误:本机未安装OutLook,或OutLook打开错误!');
End;

end;
--------------------------------------http://www.delphibbs.com/delphibbs/dispq.asp?lid=2649105
标题: 急急急!!!,用D6把一个文件夹(含内容)压缩打包/解包--(分不够可以再散)
DELPHI 中怎么让.rar文件解压到指定的目录中
 
chenybin,
你好!
我测试了这段代码,包括原贴的另外一段代码。
问题:
1。这段代码一点击“发送”就没有反应了。
2。另外那段代码,点“发送”没问题,但是结果是收不到邮件。
请再帮帮忙,万分感谢!
 
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.
 
谢谢老大!
谢谢,谢谢啊![:D]
 

Similar threads

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