那一位有邮件系统的源代码(1000分送) Delphi自带的Demos;projects\Demos\FastNet\Smtp\Smtp.dprprojects\Demos\FastNet\Pop3\Pop3.dpr 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我不是说这样的代码,而是web开发 利用Delphi编程发送E-mail接发E-mail是许多“网虫”必修的功课,E-mail工具软件也很多,国外有Microsoft的Outlook Express、The Bat等,国内则有FoxMail这样的精品。实,利用可视化编程工具Delphi4.0也能够制作出自己的E-mail软件。Delphi4.0有关E-mail的组件有两个:NmPOP3和NmSTMP,它们都位于Internet 选项卡上,其中,NmPOP3组件封装并实现POP3协议,用来从Internet POP3服务器上读取电子邮件;NmSTMP封装并实现STMP协议,可用来向Internet的STMP服务器发送电子邮件。限于篇幅,我们不能两者都介绍,这里只用NmSTMP编写一个发送E-mail的程序,至于NmPOP3,以后有机会再谈,或者在看完本文后你有兴趣,也可以借助于Delphi的帮助文档尝试用NmPOP3编程。我们先来看一下程序运行界面。图1是程序主窗体,上面有一个字符串网格(StringGrid)和三个按钮,它们的容器是仅有一个标签的PageControl。单击“Clear”钮清除网格内容,单击“Send”钮发送E-mail,单击“New Mail”钮弹出图2所示的对话框,此对话框用来设置STMP服务器名称、发件人地址、收件人地址、发件人名称和邮件主题,其中前三项必须填写,“Select File”按钮用来打开Open对话框,以便选取要发送的附件。NmSTMP的属性和方法不多,关键的属性是Host(STMP服务器名称)和PostMessage (包含邮件信息),正确设置了Host属性和PostMessage属性后,就可以用Connect 方法(连接服务器)和SendMail方法发送E-mail了。编写代码之前先要改变StringGrid1的一些缺省属性:ColCount属性为6, FixedCols属性为0,RowCount属性为2,另外,将PageControl1的Align属性置为alClient。以下是Unit1(主窗体)代码清单:unit Unit1;interfaceusesWindowsMessagesSysUtilsClassesGraphicsControlsFormsDialogsGridsComCtrlsStdCtrlsPsockNMsmtp;typeTForm1 = class(TForm)PageControl1: TPageControl;TabSheet1: TTabSheet;StatusBar1: TStatusBar;StringGrid1: TStringGrid;Button1: TButton;Button2: TButton;Button3: TButton;NMSMTP1: TNMSMTP;procedure FormCreate(Sender: TObject);procedure Button1Click(Sender: TObject);procedure Button2Click(Sender: TObject);procedure Button3Click(Sender: TObject);procedure NMSMTP1Failure(Sender: TObject);procedure NMSMTP1SendStart(Sender: TObject);procedure NMSMTP1Success(Sender: TObject);private{ Private declarations }public{ Public declarations }end;varForm1: TForm1;implementationuses Unit2;{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);beginPageControl1.Pages[0].Caption:=‘Send Mail’;self.Caption:=‘My Mailer’;self.BorderIcons:=[biSystemMenubiMinimize];self.BorderStyle:=bsSingle;Application.Icon:=self.Icon;Application.Title:=self.Caption;with StringGrid1 dobeginCells[00]:=‘Host’;Cells[10]:=‘To Address’;Cells[20]:=‘From Address’;Cells[30]:=‘Your Name’;Cells[40]:=‘Subject’;Cells[50]:=‘File’;end;Button2.Enabled:=False;Button3.Enabled:=False;end;procedure TForm1.Button1Click(Sender: TObject);beginForm2.Show;end;procedure TForm1.Button2Click(Sender: TObject);vari:Integer;beginfor i:=1 to StringGrid1.RowCount-2 dowith Nmsmtp1 dobeginHost:=StringGrid1.Cells[0i];PostMessage.ToAddress.Add(StringGrid1.Cells[1i]);PostMessage.FromAddress:=StringGrid1.Cells[2i];PostMessage.FromName:=StringGrid1.Cells[3i];PostMessage.Subject:=StringGrid1.Cells[4i];PostMessage.Attachments.Add(StringGrid1.Cells[5i]);Connect;Sendmail;DisConnect;end;Button2.Enabled:=False;Button3.Click;end;procedure TForm1.Button3Click(Sender: TObject);vari:Integer;beginwith StringGrid1 dobeginfor i:=1 to RowCount-2 dobeginCells[0i]:=‘’;Cells[1i]:=‘’;Cells[2i]:=‘’;Cells[3i]:=‘’;Cells[4i]:=‘’;Cells[5i]:=‘’;end;RowCount:=2;end;Button2.Enabled:=False;Button3.Enabled:=False;end;procedure TForm1.NMSMTP1Failure(Sender: TObject);beginStatusBar1.SimpleText:=‘Mail send failure!’;end;procedure TForm1.NMSMTP1SendStart(Sender: TObject);beginStatusBar1.SimpleText:=‘Now Sending...’;end;procedure TForm1.NMSMTP1Success(Sender: TObject);beginStatusBar1.SimpleText:=‘Send Success!’;end;end.Button1是“New Mail”按钮,Button 2是“Send”按钮,Button3是“Clear” 按钮。以下是Unit2代码清单:unit Unit2;interfaceusesWindowsMessagesSysUtilsClassesGraphicsControlsFormsDialogsStdCtrls;typeTForm2 = class(TForm)OpenDialog1: TOpenDialog;GroupBox1: TGroupBox;GroupBox2: TGroupBox;Edit1: TEdit;Edit2: TEdit;Edit3: TEdit;Edit4: TEdit;Edit5: TEdit;Button1: TButton;Button2: TButton;Button3: TButton;Label1: TLabel;Label2: TLabel;Label3: TLabel;Label4: TLabel;Label5: TLabel;Label6: TLabel;procedure Button1Click(Sender: TObject);procedure Button2Click(Sender: TObject);procedure Button3Click(Sender: TObject);procedure FormActivate(Sender: TObject);procedure FormCreate(Sender: TObject);private{ Private declarations }public{ Public declarations }end;varForm2: TForm2;implementationuses Unit1;{$R *.DFM}procedure TForm2.FormCreate(Sender: TObject);beginself.Caption:=‘New Mail’;self.BorderStyle:=bsDialog;end;procedure TForm2.FormActivate(Sender: TObject);beginEdit1.Text:=‘’;Edit2.Text:=‘’;Edit3.Text:=‘’;Edit4.Text:=‘’;Edit5.Text:=‘’;Label1.Caption:=‘No File’;end;procedure TForm2.Button1Click(Sender: TObject);beginif OpenDialog1.Execute thenLabel1.Caption:=Opendialog1.Filename;end;procedure TForm2.Button2Click(Sender: TObject);vari:Integer;beginif (Edit1.Text<>‘’) and (Edit2.Text<>‘’) and (Edit5.Text<>‘’)and (Label1.Caption<>‘No File’) thenbeginwith Form1.StringGrid1 dobeginRowCount:=RowCount+1;i:=RowCount-2;Cells[0i]:=Edit1.Text;Cells[1i]:=Edit2.Text;Cells[2i]:=Edit5.Text;Cells[3i]:=Edit3.Text;Cells[4i]:=Edit4.Text;Cells[5i]:=Label1.Caption;end;Form1.Button2.Enabled:=True;Form1.Button3.Enabled:=True;end;self.Hide;end;procedure TForm2.Button3Click(Sender: TObject);beginself.Hide;end;end.Edit1、Edit2、Edit3、Edit4、Edit5编辑框分别用于填写服务器名称、收件人地址、发件人名称、邮件主题和发件人地址。 请高手指教,有关结构问题 哪里错了 (超紧急)能不能在已经查询出来的recordset中添加一个字段并给予赋值? 请问如何打印出分子式!!救命啊!!各位大哥!!高分求解!!! 请问各位高手,如何把一个文件夹压缩,并将其作为附件通过email发送出去。谢谢! 讨论一下B/S结构下internet嵌入WORD问题 怎样用OLE方式调用windows附件画图mspaint.exe 菜鸟再次求教SQL语句的写法(//bow) StringGrid单元的颜色 如何使用向上箭头上移控件的! 报表事件? 如何在DBedit组件中显示money类型的数据为¥250.00的格式?急!!
钮弹出图2所示的对话框,此对话框用来设置STMP服务器名称、发件人地址、收件人地址、发件人名称和邮件主题,其中前三项必须填写,“Select File”按钮用来打开Open对话框,以便选取要发送的附件。NmSTMP的属性和方法不多,关键的属性是Host(STMP服务器名称)和PostMessage (包含邮件信息),正确设置了Host属性和PostMessage属性后,就可以用Connect 方法(连接服务器)和SendMail方法发送E-mail了。编写代码之前先要改变StringGrid1的一些缺省属性:ColCount属性为6, FixedCols属性为0,RowCount属性为2,另外,将PageControl1的Align属性置为alClient。以下是Unit1(主窗体)代码清单:
unit Unit1;
interface
uses
WindowsMessagesSysUtilsClassesGraphicsControlsFormsDialogsGridsComCtrlsStdCtrlsPsockNMsmtp;
type
TForm1 = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
StatusBar1: TStatusBar;
StringGrid1: TStringGrid;
Button1: TButton;
Button2: TButton;
Button3: TButton;
NMSMTP1: TNMSMTP;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure NMSMTP1Failure(Sender: TObject);
procedure NMSMTP1SendStart(Sender: TObject);
procedure NMSMTP1Success(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
PageControl1.Pages[0].Caption:=‘Send Mail’;
self.Caption:=‘My Mailer’;
self.BorderIcons:=[biSystemMenubiMinimize];
self.BorderStyle:=bsSingle;
Application.Icon:=self.Icon;
Application.Title:=self.Caption;
with StringGrid1 do
begin
Cells[00]:=‘Host’;
Cells[10]:=‘To Address’;
Cells[20]:=‘From Address’;
Cells[30]:=‘Your Name’;
Cells[40]:=‘Subject’;
Cells[50]:=‘File’;
end;
Button2.Enabled:=False;
Button3.Enabled:=False;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Form2.Show;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i:Integer;
begin
for i:=1 to StringGrid1.RowCount-2 do
with Nmsmtp1 do
begin
Host:=StringGrid1.Cells[0i];
PostMessage.ToAddress.Add(StringGrid1.Cells[1i]);
PostMessage.FromAddress:=StringGrid1.Cells[2i];
PostMessage.FromName:=StringGrid1.Cells[3i];
PostMessage.Subject:=StringGrid1.Cells[4i];
PostMessage.Attachments.Add(StringGrid1.Cells[5i]);
Connect;
Sendmail;
DisConnect;
end;
Button2.Enabled:=False;
Button3.Click;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
i:Integer;
begin
with StringGrid1 do
begin
for i:=1 to RowCount-2 do
begin
Cells[0i]:=‘’;
Cells[1i]:=‘’;
Cells[2i]:=‘’;
Cells[3i]:=‘’;
Cells[4i]:=‘’;
Cells[5i]:=‘’;
end;
RowCount:=2;
end;
Button2.Enabled:=False;
Button3.Enabled:=False;
end;
procedure TForm1.NMSMTP1Failure(Sender: TObject);
begin
StatusBar1.SimpleText:=‘Mail send failure!’;
end;
procedure TForm1.NMSMTP1SendStart(Sender: TObject);
begin
StatusBar1.SimpleText:=‘Now Sending...’;
end;
procedure TForm1.NMSMTP1Success(Sender: TObject);
begin
StatusBar1.SimpleText:=‘Send Success!’;
end;
end.
Button1是“New Mail”按钮,Button 2是“Send”按钮,Button3是“Clear” 按钮。
以下是Unit2代码清单:
unit Unit2;
interface
uses
WindowsMessagesSysUtilsClassesGraphicsControlsFormsDialogsStdCtrls;
type
TForm2 = class(TForm)
OpenDialog1: TOpenDialog;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses Unit1;
{$R *.DFM}
procedure TForm2.FormCreate(Sender: TObject);
begin
self.Caption:=‘New Mail’;
self.BorderStyle:=bsDialog;
end;
procedure TForm2.FormActivate(Sender: TObject);
begin
Edit1.Text:=‘’;
Edit2.Text:=‘’;
Edit3.Text:=‘’;
Edit4.Text:=‘’;
Edit5.Text:=‘’;
Label1.Caption:=‘No File’;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
Label1.Caption:=Opendialog1.Filename;
end;
procedure TForm2.Button2Click(Sender: TObject);
var
i:Integer;
begin
if (Edit1.Text<>‘’) and (Edit2.Text<>‘’) and (Edit5.Text<>‘’)
and (Label1.Caption<>‘No File’) then
begin
with Form1.StringGrid1 do
begin
RowCount:=RowCount+1;
i:=RowCount-2;
Cells[0i]:=Edit1.Text;
Cells[1i]:=Edit2.Text;
Cells[2i]:=Edit5.Text;
Cells[3i]:=Edit3.Text;
Cells[4i]:=Edit4.Text;
Cells[5i]:=Label1.Caption;
end;
Form1.Button2.Enabled:=True;
Form1.Button3.Enabled:=True;
end;
self.Hide;
end;
procedure TForm2.Button3Click(Sender: TObject);
begin
self.Hide;
end;
end.
Edit1、Edit2、Edit3、Edit4、Edit5编辑框分别用于填写服务器名称、收件人地址、发件人名称、邮件主题和发件人地址。