ufrmNewSMTP.pas
上传用户:yjb1804
上传日期:2021-01-30
资源大小:3105k
文件大小:3k
- unit ufrmNewSMTP;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, cxMaskEdit, cxButtonEdit, cxControls, cxContainer, cxEdit,
- cxTextEdit, StdCtrls, ExtCtrls, Menus, cxLookAndFeelPainters, cxButtons,nativexml,
- JvBaseDlg, JvSelectDirectory;
- type
- TfrmNewSMTP = class(TForm)
- Panel1: TPanel;
- lbl1: TLabel;
- lbl2: TLabel;
- lbl4: TLabel;
- edtPopServer: TcxTextEdit;
- edtEmailAccunt: TcxTextEdit;
- edtPwd: TcxTextEdit;
- edtSaveTo: TcxButtonEdit;
- Label1: TLabel;
- Panel2: TPanel;
- btnOk: TcxButton;
- btnCancel: TcxButton;
- Image1: TImage;
- SelectDir: TJvSelectDirectory;
- procedure edtSaveToPropertiesButtonClick(Sender: TObject;
- AButtonIndex: Integer);
- procedure FormCreate(Sender: TObject);
- procedure btnOkClick(Sender: TObject);
- private
- { Private declarations }
- FXml:TNativeXml;
- function CheckInput:Boolean;
- function UserExsit(EmailAddr:string):Boolean;
- //procedure InitData;
- public
- { Public declarations }
- end;
- var
- frmNewSMTP: TfrmNewSMTP;
- implementation
- uses uCommon, ufrmMain, uMyXml;
- {$R *.dfm}
- function TfrmNewSMTP.CheckInput: Boolean;
- begin
- Result:=False;
- if (edtPopServer.Text='') then
- begin
- ShowMessage('pop3服务器地址不能为空');
- Exit;
- end;
- if (edtSaveTo.Text='') then
- begin
- ShowMessage('邮件保存路径不能为空');
- Exit;
- end;
- if not TEMailAddress.IsEmail(edtEmailAccunt.Text) then
- begin
- ShowMessage('不是有效的邮箱账号');
- Exit;
- end;
- if (edtPwd.Text='') then
- begin
- ShowMessage('邮箱密码不能为空');
- Exit;
- end;
- if UserExsit(trim(edtEmailAccunt.Text)) then
- begin
- ShowMessage('邮箱账号已经存在!');
- Exit;
- end;
- Result:=True;
- end;
- procedure TfrmNewSMTP.edtSaveToPropertiesButtonClick(Sender: TObject;
- AButtonIndex: Integer);
- begin
- if SelectDir.Execute then
- edtSaveTo.Text:=SelectDir.Directory;
- end;
- procedure TfrmNewSMTP.FormCreate(Sender: TObject);
- begin
- Fxml:=TNativeXml.Create;
- Fxml.LoadFromFile(AppPath+'EmailServers.xml');
- end;
- function TfrmNewSMTP.UserExsit(EmailAddr:string): Boolean;
- var
- smtp:TList;
- //ANode:TXmlNode;
- I:Integer;
- begin
- Result:=False;
- if (FXml.Root=nil) or (FXml.Root.NodeByName('pop3s')=nil) then Exit;
- smtp:=TList.Create;
- try
- FXml.Root.NodeByName('pop3s').NodesByName('pop3',smtp);
- if smtp.Count=0 then Exit;
- for I:=0 to smtp.Count-1 do
- if (EmailAddr= TXmlNode(smtp[I]).NodeByName('emailaddr').ValueAsString) then
- begin
- result:=True;
- Exit;
- end;
- finally
- smtp.Free;
- end;
- end;
- procedure TfrmNewSMTP.btnOkClick(Sender: TObject);
- var
- MyXml:TMyXml;
- begin
- if not CheckInput then Exit;
- MyXml:=TMyXml.Create(AppPath+'EmailServers.xml');
- try
- MyXml.NewPop3(edtPopServer.Text,edtEmailAccunt.Text,edtPwd.Text,edtSaveto.Text);
- finally
- MyXml.Free;
- end;
- ufrmMain.frmMain.LoadEmails(frmMain.tvEMail);
- self.ModalResult:=mrOk;
- end;
- end.