再论---如何调用EMAIL的客户端发送邮件时如何指定邮件的地址,标题,内容,附件?(10分)

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

mycwcgr

Unregistered / Unconfirmed
GUEST, unregistred user!
to:terry_lzs
您的程序在wondows 2000中执行正常,
为什么在WINDOWS 98中不正常


来自:terry_lzs, 时间:2001-6-6 10:09:58, ID:555554
测试过的,可以用,你在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.


 
to terry_lzs:
真是是很奇怪,我在 windows 2000能正常通过
但是我在中文windows 98 英文windows中都试过了
在运行时仅仅是屏幕闪了一下,没有启动 outlook
这是我写的您帮助我看一看,其中FUNCTION SendEMail的位置加对了没有?
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'] := 'c:/autoexec.bat';//附件路径要存在
sendEMail(Application.Handle, mail);
mail.Free;
end;


end.

 
另外下面一段程序您能调试通过吗?

const olMailItem = 0;
var Outlook: OLEVariant;
MailItem: Variant;
begin

try
Outlook := GetActiveOleObject('Outlook.Application');
except
Outlook := CreateOleObject('Outlook.Application');
end;

MailItem := Outlook.CreateItem(olMailItem);
MailItem.Recipients.Add('mshkolnik@rs-ukraine.kiev.ua');
MailItem.Subject := 'your subject';
MailItem.Body := 'Welcome to my homepage:http://www.geocities.com/mshkolnik';
MailItem.Attachments.Add('C:/Windows/Win.ini');
MailItem.Send;
Outlook := Unassigned;
end;
 
1、同样的代码,我在办公室 windows 2000中一点问题没有
在家里windows 95中却不行。
2、思前想后,我想在家里是不是因为安装了FOXMAIL软件的原因?
后来我将outlook也配置好,并设置为默认邮件程序,却还是不行
为什么?outlook还要怎样配置,我的WINDOWS 98 的VERSION 为4.10.2222A
3、第二段代码我测试也通不过,似乎还是outlook没有配置好,难道您的outlook
是单独安装的,我是在安装windows 98 时自动安装上去的,从来没有改过
 
mycwcgr:你的問題已經過期,請自己提前或結束,謝謝
 
另外一段调用是OFFICE里的OUTLOOK,
而你前面的第一段程序是根据你默认的邮件系统来的。
 
多人接受答案了。
 
后退
顶部