📄 postmsg.pas
字号:
unit PostMsg;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdMessage, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdMessageClient, IdSMTP, ExtCtrls, StdCtrls, Buttons,
ComCtrls;
type
TFormMailMsg = class(TForm)
StatusBar1: TStatusBar;
GroupBox1: TGroupBox;
Label1: TLabel;
ToLabeledEdit: TLabeledEdit;
SubjectLabeledEdit: TLabeledEdit;
CCLabeledEdit: TLabeledEdit;
BCCLabeledEdit: TLabeledEdit;
PriorityCBO: TComboBox;
ReturnRecieptCHK: TCheckBox;
GroupBox_Memo: TGroupBox;
EMailMemo: TMemo;
GroupBox3: TGroupBox;
FilesListView: TListView;
AttachmentBTN: TBitBtn;
Panel_BTN: TPanel;
BTNOK: TBitBtn;
CancelBTN: TBitBtn;
OpenDialog1: TOpenDialog;
SMTP: TIdSMTP;
MsgSend: TIdMessage;
BTNSetting: TBitBtn;
Panel_Address: TPanel;
Splitter1: TSplitter;
procedure BTNOKClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure AttachmentBTNClick(Sender: TObject);
procedure CancelBTNClick(Sender: TObject);
private
{ Private declarations }
procedure ResetAttachmentListView; { 重置附件列表 }
public
{ Public declarations }
end;
var
FormMailMsg: TFormMailMsg;
implementation
uses main;
{$R *.dfm}
procedure TFormMailMsg.BTNOKClick(Sender: TObject);
begin
if pos('@', trim(ToLabeledEdit.Text)) <= 0 then
begin
Showmessage('非法的收件地址!');
exit;
end;
with MsgSend do
begin
Body.Assign(EMailMemo.Lines);
From.Text := UserMailBox;
ReplyTo.EMailAddresses := UserMailBox;
Recipients.EMailAddresses := ToLabeledEdit.Text; { 目的地 }
Subject := SubjectLabeledEdit.Text; { 标题 }
Priority := TIdMessagePriority(PriorityCBO.ItemIndex); { 优先级 }
CCList.EMailAddresses := CCLabeledEdit.Text; { 抄送 }
BccList.EMailAddresses := BCCLabeledEdit.Text; { 暗送 }
if ReturnRecieptCHK.Checked then
begin {设置发送回执为E-Mail地址 }
ReceiptRecipient.Text := From.Text;
end
else
begin {无发送回执}
ReceiptRecipient.Text := '';
end;
end;
{ 验证设置 }
case SmtpAuthType of
0: SMTP.AuthenticationType := atNone;
1: SMTP.AuthenticationType := atLogin; {Simple Login}
end;
SMTP.Username := SmtpServerUser;
SMTP.Password := SmtpServerPassword;
{ 一般设置 }
SMTP.Host := SmtpServerName;
SMTP.Port := SmtpServerPort;
{ 以下为发送邮件并显示提示信息 }
SMTP.Connect; { 连接SMTP服务器 }
try
StatusBar1.Panels[0].Text := '正在发送电子邮件...请稍等!';
SMTP.Send(MsgSend); { 发送邮件 }
finally
SMTP.Disconnect; { 断开连接 }
StatusBar1.Panels[0].Text := '邮件发送成功!';
end;
end;
procedure TFormMailMsg.FormCreate(Sender: TObject);
begin
PriorityCBO.ItemIndex := Ord(MsgSend.Priority);
end;
procedure TFormMailMsg.AttachmentBTNClick(Sender: TObject);
begin
OpenDialog1.Title := '请选择文件!';
OpenDialog1.Filter := '优利聊天文件(*.cat)|*.cat|各种文件(*.*)|*.*';
if OpenDialog1.Execute then
begin
TIdAttachment.Create(MsgSend.MessageParts, OpenDialog1.FileName);
ResetAttachmentListView;
end;
end;
{ 刷新附件列表 }
procedure TFormMailMsg.ResetAttachmentListView;
var li: TListItem;
idx: Integer;
begin
FilesListView.Items.Clear;
for idx := 0 to Pred(MsgSend.MessageParts.Count) do
begin
li := FilesListView.Items.Add;
if MsgSend.MessageParts.Items[idx] is TIdAttachment then
begin
li.ImageIndex := 0;
li.Caption := TIdAttachment(MsgSend.MessageParts.Items[idx]).Filename;
li.SubItems.Add(TIdAttachment(MsgSend.MessageParts.Items[idx]).ContentType);
end
else
begin
li.ImageIndex := 1;
li.Caption := MsgSend.MessageParts.Items[idx].ContentType;
end;
end;
end;
procedure TFormMailMsg.CancelBTNClick(Sender: TObject);
begin
Self.Close;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -