关于Smtp(100分)

  • 主题发起人 主题发起人 smilboy
  • 开始时间 开始时间
S

smilboy

Unregistered / Unconfirmed
GUEST, unregistred user!
可否给一个用Delphi编的最简单的发送邮件程序例子(发送memo中的文本),要用smtp
 
看看DELPHI3中internet的例子
 
delphi4的demos/internet/smtp有详细的例子
 
我明天给你一个Cool,我现在要出去
 
//程序的一部分
unit Automail;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls, Menus, Psock, NMsmtp, ToolWin, ComCtrls, Db,
DBTables, jpeg, NMNNTP;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
T1: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
ToolBar1: TToolBar;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
BitBtn4: TBitBtn;
Table1: TTable;
GroupBox1: TGroupBox;
Button2: TButton;
Panel1: TPanel;
Label1: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
SpeedButton1: TSpeedButton;
Label4: TLabel;
Label5: TLabel;
Edit3: TEdit;
Edit4: TEdit;
Button3: TButton;
OpenDialog1: TOpenDialog;
BitBtn5: TBitBtn;
N5: TMenuItem;
N6: TMenuItem;
Memo1: TMemo;
SpeedButton2: TSpeedButton;
ListBox1: TListBox;
BitBtn6: TBitBtn;
N7: TMenuItem;
N8: TMenuItem;
StatusBar1: TStatusBar;
W1: TMenuItem;
NMSMTP1: TNMSMTP;
procedure BitBtn1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn4Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure NMSMTP1Connect(Sender: TObject);
procedure NMSMTP1Status(Sender: TComponent;
Status: String);
procedure NMSMTP1ConnectionFailed(Sender: TObject);
procedure NMSMTP1ConnectionRequired(var handled: Boolean);
procedure NMSMTP1SendStart(Sender: TObject);
procedure NMSMTP1Success(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure NMSMTP1InvalidHost(var Handled: Boolean);
procedure NMSMTP1HeaderIncomplete(var handled: Boolean;hiType: Integer);
procedure NMSMTP1HostResolved(Sender: TComponent);
procedure BitBtn5Click(Sender: TObject);
procedure Memo1Change(Sender: TObject);
procedure N6Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
procedure BitBtn6Click(Sender: TObject);
procedure N8Click(Sender: TObject);
procedure NMSMTP1Authen
ticationFailed(var Handled: Boolean);
procedure NMSMTP1PacketSent(Sender: TObject);
procedure NMSMTP1RecipientNotFound(Recipient: String);
private
{ Private declarations }
AllowAutoSend : Boolean;
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
uses MailList,Pub, List, HostEdit, ErrInfo;
{$R *.DFM}
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
MailAdr.show;
mailadr.Edit1.Text:='';
end;

procedure TForm1.NMSMTP1Connect(Sender: TObject);
begin
statusBar1.SimpleText:='已经连接,正在进行自动邮件处理';
AllowAutoSend := True;
StartSend := True;
end;

procedure TForm1.Button2Click(Sender: TObject);
var i : integer;
begin

if not AllowAutosend then
exit;
NMSMTP1.PostMessage.FromAddress :='wdou@263.net';
NMSMTP1.PostMessage.FromName := '故障信息';
if ListFrm.Edit1.Text <> '' then
begin
NMSMTP1.PostMessage.Subject := ListFrm.Edit1.Text ;
NmSmtp1.PostMessage.ToAddress.Clear ;
for i := 0 to Listbox1.Items.Count - 1do
NMSMTP1.PostMessage.ToAddress.Add(Listbox1.Items.Strings);
//NMSMTP1.PostMessage.ToAddress.Add('douw@cumt.edu.cn');
//NMSMTP1.PostMessage.ToBlindCarbonCopy.Add(Edit9.Text);
//NMSMTP1.PostMessage.ToCarbonCopy.Add(Edit8.Text);
//NMSMTP1.PostMessage.Attachments.AddStrings(Listbox1.Items);
NMSMTP1.PostMessage.Body.Assign(ListFrm.Memo1.lines);
NMSMTP1.SendMail;
end;
end;

procedure Tform1.NMSMTP1SendStart(Sender:Tobject);
begin
//label2.Caption:='发送电子邮件';
statusBar1.SimpleText:='发送电子邮件';
end;

procedure Tform1.NMSMTP1ConnectionFailed(Sender:Tobject);
begin
//label2.Caption:='连接失败';
statusBar1.SimpleText:='连接失败';
StartSend := False;
end;

procedure Tform1.NMSMTP1ConnectionRequired(var handled:boolean);
begin
IF Messagedlg('是否连接主机?',mtConfirmation,
mbOKCancel,0)=mrOK then
begin
Handled:=TRUE;
NMSMTP1.Connect;
end;

end;

procedure TForm1.NMSMTP1Success(Sender: TObject);
begin
//label2.caption := '成功';
StatusBar1.SimpleText:='成功';
end;

procedure TForm1.NMSMTP1Status(Sender: TComponent;
Status: String);
begin
//if label2.Caption<>'' then
// label2.Caption:='状态';
if statusbar1.simpletext<> '' then
statusbar1.simpletext:='状态';
end;

procedure TForm1.N2Click(Sender: TObject);
begin
close;
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
begin
hostmes.show;
end;

procedure TForm1.BitBtn3Click(Sender: TObject);
begin
infoDb.SHow;
end;

procedure TForm1.BitBtn4Click(Sender: TObject);
begin
GroupBox1.Visible := not GroupBox1.Visible ;
//Bevel1.Visible := not bevel1.Visible ;
//Button2.visible :=NOT GroupBox1.Visible ;
Listbox1.visible := not listbox1.Visible ;
//label2.Visible := not label2.Visible ;
if edit1.text<> '' then
edit1.text:= '';
if edit2.text<> '' then
edit2.text:= '';
if edit3.text<> '' then
edit3.text:= '';
if edit4.text<> '' then
edit4.text:= '';
memo1.Clear;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
AllowAutoSend := False;
StartSend := False;
if FileExists('Mailadr.lst') then
Listbox1.Items.LoadFromFile('mailAdr.lst');
button2.Hide;

end;


procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
NMSMTP1.PostMessage.ToAddress.Add(edit1.Text );
NMSMTP1.PostMessage.FromAddress :=edit2.Text;
NMSMTP1.PostMessage.Subject := Edit3.Text ;
NMSMTP1.PostMessage.Attachments.Add(Edit4.Text);
NMSMTP1.PostMessage.Body.Assign(Memo1.lines);
NMSMTP1.SendMail;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
NMSMTP1.Disconnect;
LIstfrm.Timer1.Enabled := False;
end;

procedure TForm1.NMSMTP1InvalidHost(var Handled: Boolean);
var TmpStr :String;
begin
if InputQuery('错误的主机名!','指定一个新的主机名:',tmpstr)
then
begin
NMSMTP1.Host:=tmpstr;
handled:=true;
end;
end;

procedure TForm1.NMSMTP1HeaderIncomplete(var handled: Boolean;
hiType: Integer);
begin
showmessage('标题不完整');
end;

procedure TForm1.NMSMTP1HostResolved(Sender: TComponent);
begin
// label2.Caption:='失败';
statusbar1.SimpleText:='失败';
end;

procedure TForm1.BitBtn5Click(Sender: TObject);
begin
if self.OpenDialog1.Execute then
Edit4.Text := self.OpenDialog1.FileName ;
end;

procedure TForm1.Memo1Change(Sender: TObject);
begin
memo1.Clear;
end;

procedure TForm1.N6Click(Sender: TObject);
begin
mailadr.show;
end;

procedure TForm1.SpeedButton2Click(Sender: TObject);
begin

listbox1.Left := speedbutton2.Left +speedbutton2.width;
listbox1.Top := SpeedButton2.Top;
listbox1.Height := 100;
listbox1.Width := 200;
listbox1.Visible := not listbox1.Visible;

end;

procedure TForm1.ListBox1Click(Sender: TObject);
begin
edit1.Text := Listbox1.Items[Listbox1.itemindex];
Listbox1.Visible := False;
end;

procedure TForm1.BitBtn6Click(Sender: TObject);
begin
NMSMTP1.Host := hostmes.Edit1.Text;
NMSMTP1.Port := 25;
NMSMTP1.UserID := hostmes.Edit2.Text;
NMSMTP1.Connect;
end;

procedure TForm1.N8Click(Sender: TObject);
begin
listfrm.show;
end;

procedure TForm1.NMSMTP1Authen
ticationFailed(var Handled: Boolean);
begin
showmessage('用户认证错');
end;

procedure TForm1.NMSMTP1PacketSent(Sender: TObject);
begin
statusbar1.SimpleText:='已发送出';
end;

procedure TForm1.NMSMTP1RecipientNotFound(Recipient: String);
begin
statusbar1.SimpleText:='找不到容纳器';
end;

end.
 
接受答案了.
 
后退
顶部