📄 postmailfrm.pas
字号:
unit PostMailFrm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
NMsmtp, Psock, NMpop3, ComCtrls, StdCtrls;
type
TForm_PostMail = class(TForm)
NMPOP31: TNMPOP3;
NMSMTP1: TNMSMTP;
Pg_PostMail: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
TabSheet4: TTabSheet;
StatusBar1: TStatusBar;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Label4: TLabel;
Edit4: TEdit;
Label5: TLabel;
Edit5: TEdit;
Label6: TLabel;
Edit6: TEdit;
Label7: TLabel;
Memo1: TMemo;
Label8: TLabel;
Button4: TButton;
ListBox1: TListBox;
Label9: TLabel;
Edit7: TEdit;
Label10: TLabel;
Edit8: TEdit;
Button5: TButton;
Label11: TLabel;
Edit9: TEdit;
Label12: TLabel;
Label13: TLabel;
Edit10: TEdit;
Edit11: TEdit;
Button6: TButton;
Label14: TLabel;
ListBox2: TListBox;
Button7: TButton;
Label15: TLabel;
Label16: TLabel;
Label17: TLabel;
Edit12: TEdit;
Edit13: TEdit;
Edit14: TEdit;
Memo2: TMemo;
Memo3: TMemo;
Button8: TButton;
Button9: TButton;
Button10: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure NMSMTP1Connect(Sender: TObject);
procedure NMSMTP1Disconnect(Sender: TObject);
procedure NMSMTP1Status(Sender: TComponent; Status: String);
procedure Button4Click(Sender: TObject);
procedure NMSMTP1EncodeStart(Filename: String);
procedure NMSMTP1EncodeEnd(Filename: String);
procedure NMSMTP1ConnectionFailed(Sender: TObject);
procedure NMSMTP1ConnectionRequired(var Handled: Boolean);
procedure NMSMTP1Failure(Sender: TObject);
procedure NMSMTP1InvalidHost(var Handled: Boolean);
procedure NMSMTP1RecipientNotFound(Recipient: String);
procedure NMSMTP1SendStart(Sender: TObject);
procedure NMSMTP1Success(Sender: TObject);
procedure NMSMTP1HeaderIncomplete(var handled: Boolean;
hiType: Integer);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure NMPOP31List(Msg, Size: Integer);
procedure Button7Click(Sender: TObject);
procedure NMPOP31Failure(Sender: TObject);
procedure NMPOP31Connect(Sender: TObject);
procedure NMPOP31ConnectionFailed(Sender: TObject);
procedure NMPOP31ConnectionRequired(var Handled: Boolean);
procedure NMPOP31InvalidHost(var Handled: Boolean);
procedure NMPOP31RetrieveEnd(Sender: TObject);
procedure NMPOP31RetrieveStart(Sender: TObject);
procedure NMPOP31Status(Sender: TComponent; Status: String);
procedure NMPOP31Success(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button8Click(Sender: TObject);
procedure NMSMTP1AuthenticationFailed(var Handled: Boolean);
procedure Button9Click(Sender: TObject);
procedure Pg_PostMailChange(Sender: TObject);
procedure Button10Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form_PostMail: TForm_PostMail;
implementation
uses AutoMenuFrm;
{$R *.DFM}
procedure TForm_PostMail.Button1Click(Sender: TObject);
begin
NMSMTP1.ClearParameters;
if not NMSMTP1.connected then
begin
NMSMTP1.Host:=edit1.Text;
NMSMTP1.Port:=StrToInt(edit2.Text);
NMSMTP1.UserID:=edit3.Text;
NMSMTP1.Connect;
end;
end;
procedure TForm_PostMail.Button2Click(Sender: TObject);
begin
if NMSMTP1.connected then NMSMTP1.Disconnect;
end;
procedure TForm_PostMail.Button3Click(Sender: TObject);
var
tmpstr:string;
begin
tmpstr:=edit3.Text;
if NMSMTP1.Verify(tmpstr) then
showmessage('ok')
else
showmessage('no');
end;
procedure TForm_PostMail.NMSMTP1Connect(Sender: TObject);
begin
statusbar1.SimpleText:='connect';
end;
procedure TForm_PostMail.NMSMTP1Disconnect(Sender: TObject);
begin
if statusbar1<>nil then
statusbar1.SimpleText:='disconnect';
end;
procedure TForm_PostMail.NMSMTP1Status(Sender: TComponent; Status: String);
begin
if statusbar1<>nil then
statusbar1.SimpleText:=status;
end;
procedure TForm_PostMail.Button4Click(Sender: TObject);
function changestr(mystr:string):TStringList;
var
tmp:string;
i:integer;
begin
changestr:=TStringList.Create;
i:=pos(';',mystr);
while i>0 do
begin
tmp:=copy(mystr,1,i-1);
changestr.Add(tmp);
delete(mystr,1,i);
i:=pos(';',mystr);
end;
changestr.Add(mystr);
end;
begin
with NMSMTP1.PostMessage do
begin
FromName:=trim(edit7.Text);
FromAddress:=trim(edit8.Text);
subject:=edit6.Text;
//attachments.AddStrings(listbox1.Items);
body.Assign(memo1.Lines);
toaddress.Clear;
//toblindcarboncopy.Clear;
//tocarboncopy.Clear;
ToAddress:=changestr(edit4.Text);
//ToCarboncopy:=changestr(edit5.Text);
end;
NMSMTP1.SendMail;
end;
procedure TForm_PostMail.NMSMTP1EncodeStart(Filename: String);
begin
statusbar1.SimpleText:='translating... '+Filename;
end;
procedure TForm_PostMail.NMSMTP1EncodeEnd(Filename: String);
begin
statusbar1.SimpleText:='translated '+Filename;
end;
procedure TForm_PostMail.NMSMTP1ConnectionFailed(Sender: TObject);
begin
showmessage('connect failed');
end;
procedure TForm_PostMail.NMSMTP1ConnectionRequired(var Handled: Boolean);
begin
if messagedlg('connect?',mtConfirmation,mbOkCancel,0)=mrok then
begin
handled:=true;
NMSMTP1.Connect;
end;
end;
procedure TForm_PostMail.NMSMTP1Failure(Sender: TObject);
begin
statusbar1.SimpleText:='operation failed' ;
end;
procedure TForm_PostMail.NMSMTP1InvalidHost(var Handled: Boolean);
var
tmpstr:string;
begin
if InputQuery('host error','new host:',tmpstr) then
begin
NMSMTP1.Host:=tmpstr;
handled:=true;
end;
end;
procedure TForm_PostMail.NMSMTP1RecipientNotFound(Recipient: String);
begin
showmessage('receive host '+Recipient+' not found');
end;
procedure TForm_PostMail.NMSMTP1SendStart(Sender: TObject);
begin
statusbar1.SimpleText:='start send...';
end;
procedure TForm_PostMail.NMSMTP1Success(Sender: TObject);
begin
statusbar1.SimpleText:='send success';
end;
procedure TForm_PostMail.NMSMTP1HeaderIncomplete(var handled: Boolean;
hiType: Integer);
begin
showmessage('header not complete');
end;
procedure TForm_PostMail.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
begin
NMSMTP1.Abort;
if NMSMTP1.connected then NMSMTP1.Disconnect;
NMPOP31.Abort;
if NMPOP31.connected then NMPOP31.Disconnect;
end;
procedure TForm_PostMail.Button5Click(Sender: TObject);
begin
if not NMPOP31.connected then
begin
NMPOP31.AttachFilePath :='.';
NMPOP31.DeleteOnRead:=false;
NMPOP31.ReportLevel:=Status_Basic;
NMPOP31.TimeOut:=3000;
NMPOP31.Host:=trim(edit9.Text);
NMPOP31.UserID:=trim(edit10.Text);
NMPOP31.Password:=trim(edit11.Text);
NMPOP31.Connect;
end;
end;
procedure TForm_PostMail.Button6Click(Sender: TObject);
begin
if NMPOP31.connected then NMPOP31.Disconnect;
end;
procedure TForm_PostMail.NMPOP31List(Msg, Size: Integer);
begin
listbox2.Items.Add('post: '+IntToStr(Msg)+'/size:'+IntToStr(size));
end;
procedure TForm_PostMail.Button7Click(Sender: TObject);
var
j:integer;
tmp:string;
begin
tmp:=copy(listbox2.Items.Text,7,(pos('/',listbox2.Items.Text)-7));
j:=StrToInt(tmp);
//for i:=1 to 500 do
//begin
NMPOP31.GetMailMessage(j);
edit12.Text:=NMPOP31.MailMessage.From;
edit13.Text:=NMPOP31.MailMessage.Subject;
edit14.Text:=NMPOP31.MailMessage.MessageId;
memo2.Lines.Assign(NMPOP31.MailMessage.Head);
memo3.Lines.Assign(NMPOP31.MailMessage.Body);
//end;
if NMPOP31.MailMessage.Attachments.Text<>'' then
showmessage('附件:'+#10#13+NMPOP31.MailMessage.Attachments.Text);
end;
procedure TForm_PostMail.NMPOP31Failure(Sender: TObject);
begin
showmessage('Receive failed');
end;
procedure TForm_PostMail.NMPOP31Connect(Sender: TObject);
begin
statusbar1.SimpleText:='Receive mail connected';
end;
procedure TForm_PostMail.NMPOP31ConnectionFailed(Sender: TObject);
begin
showmessage('connect failed');
end;
procedure TForm_PostMail.NMPOP31ConnectionRequired(var Handled: Boolean);
begin
if messagedlg('connect?',mtConfirmation,mbOkCancel,0)=mrok then
begin
handled:=true;
NMPOP31.Connect;
end;
end;
procedure TForm_PostMail.NMPOP31InvalidHost(var Handled: Boolean);
var
tmpstr:string;
begin
if InputQuery('host error','new host:',tmpstr) then
begin
NMPOP31.Host:=tmpstr;
handled:=true;
end;
end;
procedure TForm_PostMail.NMPOP31RetrieveEnd(Sender: TObject);
begin
cursor:=crDefault;
statusbar1.SimpleText:='Receive End';
end;
procedure TForm_PostMail.NMPOP31RetrieveStart(Sender: TObject);
begin
cursor:=crHourGlass;
statusbar1.SimpleText:='Receive Start';
end;
procedure TForm_PostMail.NMPOP31Status(Sender: TComponent; Status: String);
begin
if statusbar1<>nil then
statusbar1.SimpleText:=status;
end;
procedure TForm_PostMail.NMPOP31Success(Sender: TObject);
begin
statusbar1.SimpleText:='Receive Success';
end;
procedure TForm_PostMail.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
action:=CaFree;
Form_PostMail:=nil;
end;
procedure TForm_PostMail.Button8Click(Sender: TObject);
begin
listbox2.Items.Clear;
NMPOP31.List;
end;
procedure TForm_PostMail.NMSMTP1AuthenticationFailed(var Handled: Boolean);
begin
statusbar1.SimpleText:='Authentication Failed';
end;
procedure TForm_PostMail.Button9Click(Sender: TObject);
var x:cardinal;
begin
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL',9);
if x=0 then messagebox(0,'程序超出内存','错误',0);
if x=ERROR_BAD_FORMAT then messagebox(0,'该程序非一个合法的Win32.EXE程序).','错误',0);
if x=ERROR_FILE_NOT_FOUND then messagebox(0,'指定文件没找到','错误',0);
if x=ERROR_PATH_NOT_FOUND then messagebox(0,'指定路径没找到','错误',0);
end;
procedure TForm_PostMail.Pg_PostMailChange(Sender: TObject);
begin
application.HintColor:=clAqua;
application.HintPause:=5000;
if Pg_PostMail.ActivePageIndex=0 then button9.Hint:='拨'+#13+'号'+#13+'网'+#13+'络';
end;
procedure TForm_PostMail.Button10Click(Sender: TObject);
begin
if not assigned(Form_AutoMenu) then application.CreateForm(TForm_AutoMenu,Form_AutoMenu);
Form_AutoMenu.ShowModal;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -