不用控件,用函数实现发Email,急(50分)

  • 主题发起人 主题发起人 firstlove
  • 开始时间 开始时间
F

firstlove

Unregistered / Unconfirmed
GUEST, unregistred user!
为了减轻重量 ,不用控件,用函数实现发Email,
 
搜索论坛先,很多的!
 
我是新人,不知怎么找,也心情找了,有急用,谢谢
 
自己做个函数啊!好像delphi没有这样的函数哦!!!
 
不是自己做函数,可利用API函数,只要不用控件,生成的文件小就行
注:smtp
 
自己去看smtp 和 pop3的协议。
用winsock 就可以实现。
 
就是不懂,所以才请教!!!!!!
 
初学就不要做那么难的东西嘛!
 
什么嘛,一个人不可能在什么方面都精通
 
哦~明白!对不起 :〉
 
现在很需要这方面的资料,用控件,我会,但用socket我不会..请高手多多指教...
加分.....没问题
 
http://www.delphibbs.com/delphibbs/download.asp

这里有控件
 
不用控件。。winsocket函数,因为我做的程序是没有界面的,连窗口都没有
 
没有界面的,连窗口都没有

就 不 能 用 控件 了???????????????????????????
 
怎么响应类似onconnect之类的消息!
 
如果系统中装有OUTLOOK可以使用API调用OUTLOOK发邮件!
unit SendMail;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TFm_SendMail = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Fm_SendMail: TFm_SendMail;

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 TFm_SendMail.Button1Click(Sender: TObject);
VAR
mail : TStringList ;
BEGIN
mail := TStringList.Create;
mail.values['to'] := 'aaaa@263.net';
mail.values['subject'] := 'test';
mail.values['body'] := 'Some body text (line 1)';
mail.values['body'] := 'Some more body text (line 2)';
mail.values['attachment0'] := 'D:/未命名.bmp';
mail.values['attachment1'] := 'c:/windows/wallman.bmp';
sendEMail(Application.Handle, mail);
mail.Free;
end;


end.
 
xxx.onconnect :=你写的过程
//声明要一致
 
用outlook发我试过,但会弹出一个对话框,说明现在用outlook发邮件。这样就是出于网络
安全。但我不想出现这个对话框。有没有其它方法。。。。?????
 
利用shellexceute的
自己去查一下旧可以的
 
后退
顶部