📄 unit1.~pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdMessage, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdMessageClient, IdSMTP, ExtCtrls;
type
TForm1 = class(TForm)
SMTP1: TIdSMTP;
IdMsg: TIdMessage;
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Label3: TLabel;
Memo1: TMemo;
Edit3: TEdit;
Button2: TButton;
Label6: TLabel;
Edit4: TEdit;
Label7: TLabel;
Edit5: TEdit;
Label8: TLabel;
Edit6: TEdit;
OpenDialog1: TOpenDialog;
Edit7: TEdit;
Label1: TLabel;
Label2: TLabel;
Label4: TLabel;
Label5: TLabel;
Button3: TButton;
Label9: TLabel;
ComboBox1: TComboBox;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if SMTP1.Connected then
begin
IdMsg.body.Clear;
IdMsg.Body.Assign(memo1.lines);
IdMsg.From.address := edit5.text;
IdMsg.Recipients.EMailAddresses :=edit6.text;
IdMsg.Subject:=edit4.text
end
else
begin
Showmessage('连接SMTP服务器失败!');
Exit;
end;
try
SMTP1.Send(IdMsg);
finally
showmessage('您的信件已成功发送');
SMTP1.Disconnect;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if opendialog1.Execute then
ComboBox1.Items.Add(OpenDialog1.FileName);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
close;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
SMTP1.AuthenticationType := atLogin;
if edit3.text<>'' then//当服务器地址不为空时
begin
if SMTP1.Connected then
begin
SMTP1.Disconnect();//如果已连接服务器则断开
showmessage('断开连接!');//给出断开连接提示
end
else
begin
SMTP1.Host:=edit3.Text; //连接主机的地址
SMTP1.Username:=edit2.Text;
SMTP1.Password:=edit1.Text;
SMTP1.Port:=25;
try
SMTP1.Connect();//连接主机
showmessage('连接成功!');//给出连接成功提示
except
showmessage('连接失败!');//给出连接失败提示
end;
end;
end
else
showmessage('警告:主机不能为空!');
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -