200分问一个OutLook Express的问题(200分)

  • 主题发起人 主题发起人 iseek
  • 开始时间 开始时间
I

iseek

Unregistered / Unconfirmed
GUEST, unregistred user!
如何后台调用OutLook Express,并且让其发送邮件?

我在网上找到一段代码,可以调用OutLook Express发带附件的邮件,只是每次都得用鼠标按“发送”钮,不爽。

 
//发送邮件,发送邮件有以下标记可以设置
//MAPI_LOGONUI显示登陆界面
//MAPI_NEWSESSION不使用共享session
//MAPI_DIALOG显示发送框
//MAPI_USE_DEFAULT使用默认登陆发送
所以你在发送邮件那很代码中去掉显示发送框的那个代码就可以了。
不过你就会遇到我那个问题。我们一起解决吧!如果你想出办法了,我把我的分给你。
 
呵呵,我是菜鸟一只,对网络编程更是一无所知,我上面说了,是我在网上找的一段代码,
似乎跟你说的不一样。我贴出来,给你看看:
-------------------------------------------------------------------------------
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;
 
晕,它本身不就是有发送邮件功能吗!
 
Result := MapiSendMail(0, Handle, MapiMessage,MAPI_DIALOG*Ord(Handle <> 0) OR MAPI_LOGON_UI OR MAPI_NEW_SESSION, 0);
非要我把这句给你找出来,再回头看看我上面说的内容。
把下面这句去掉就ok了MAPI_DIALOG*Ord(Handle<>0)
不能光用别人的代码,你还要理解这段代码。
 
你可以用Indy控件自己编一段程序发送邮件。/Borland/Delphi7/Demos/Indy/MailClient下有例子。不过会出现我下面帖子所述的问题:
http://www.delphibbs.com/delphibbs/DispQ.asp?LID=2121017
 
后退
顶部