如题
解决方案 »
- [转帖]建国大业
- 新手对窗口的迷惑
- HELP ADO连接EXCLE的问题 急死人了 。。。。。。。。。。。。。。解决了 马上给分 嫌少再加
- 如何使用FindComponent来调用另一个form中名字有规律的几个TEdit
- 谁有dbgrid导出到excel的快速方法?不用三方控件,不用ole,不用数据集导出的方法。
- ?help界面美化的方法及各方面??
- (在线等待)关于菜单的问题!
- 如何快速插入纪录
- 怎样使form在屏幕上的位置固定,无法被拖动?
- 获取wan口IP
- 100分寻求答案!把指定的目录下文件打包成执行文件,点击后,自动运行默认的文件,怎么处理?谢谢!!!急!!!!!
- f1book出图表
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;
Edit3: TEdit;
Label6: TLabel;
Edit4: TEdit;
Edit5: TEdit;
Label8: TLabel;
Edit6: TEdit;
Label1: TLabel;
Label2: TLabel;
Label4: TLabel;
Label5: TLabel;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
IdAtt: TIdAttachment;
begin
SMTP1.AuthenticationType := atLogin;SMTP1.username:= edit2.text;
SMTP1.Password := edit1.text;SMTP1.Host := edit3.text;
SMTP1.Port :=25;
try
SMTP1.Connect;
except
Showmessage('连接SMTP服务器失败!');
Exit;
end;
try
with IdMsg do
begin
IdAtt := TIdAttachment.Create(MessageParts, 'c:\IMG00004.jpg');
body.Clear;
Body.Assign(memo1.lines);
From.address := edit5.text;
Recipients.EMailAddresses :=edit6.text;
Subject:=edit4.text
end;
SMTP1.Send(IdMsg);
finally
IdAtt.Free;
end;end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdMessage, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdMessageClient, IdSMTP, StdCtrls, ComCtrls, ImgList,
Buttons;type
TForm1 = class(TForm)
smtpcom: TIdSMTP;
Msg: TIdMessage;
GroupBox1: TGroupBox;
Label1: TLabel;
SMTPServer: TEdit;
Label2: TLabel;
SMTPUsername: TEdit;
Label3: TLabel;
SMTPPassword: TEdit;
GroupBox2: TGroupBox;
GroupBox3: TGroupBox;
Label8: TLabel;
smtpsubject: TEdit;
Label9: TLabel;
smtpbody: TMemo;
Button3: TButton;
lvFiles: TListView;
Label10: TLabel;
StatusBar1: TStatusBar;
Label4: TLabel;
Label5: TLabel;
smtpfrom: TEdit;
smtpto: TEdit;
Label6: TLabel;
smtpbbc: TEdit;
Label7: TLabel;
smtpcc: TEdit;
Label11: TLabel;
smtpPriority: TComboBox;
ImageList1: TImageList;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
Label12: TLabel;
smtpmailagent: TEdit;
Label13: TLabel;
smtpheloname: TEdit;
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure ResetAttachmentListView();
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button2Click(Sender: TObject);
begin
smtpcom.Disconnect ;
end;procedure TForm1.Button3Click(Sender: TObject);
begin
smtpcom.Disconnect ;
smtpcom.Host :=smtpserver.Text ;
smtpcom.Username :=smtpusername.Text ;
smtpcom.Password :=smtppassword.Text ;
smtpcom.HeloName :=smtpheloname.Text ;
smtpcom.MailAgent :=smtpmailagent.Text ;
smtpcom.Connect();
//设置邮件服务器参数
with Msg do
begin
Body.Assign(smtpbody.Lines);
//填写信件正文
From.Text:=smtpfrom.text;
//填写发信人地址
Recipients.EMailAddresses :=smtpto.Text ;
//填写收信人地址
Subject:=smtpSubject.text;
//填写邮件标题
case smtpPriority.ItemIndex of
0:Msg.Priority:=mpHighest;
1:Msg.Priority :=mpHigh;
2:Msg.Priority :=mpNormal;
3:Msg.Priority :=mpLow;
4:Msg.Priority :=mpLowest;
end;
//设置发送邮件的优先级
end;
//设置发送邮件的内容
Try
smtpcom.Send(Msg);
finally
smtpcom.Disconnect ;
end;
//发送邮件
end;{*过程描述:刷新附件显示栏中的内容*}procedure TForm1.ResetAttachmentListView();
var
li: TListItem;
idx: Integer;
begin
lvFiles.Items.Clear;
for idx := 0 to Pred(Msg.MessageParts.Count) do
begin
li := lvFiles.Items.Add;
if Msg.MessageParts.Items[idx] is TIdAttachment then
begin
li.ImageIndex := 0;
li.Caption := TIdAttachment(Msg.MessageParts.Items[idx]).Filename;
li.SubItems.Add(TIdAttachment(Msg.MessageParts.Items[idx]).ContentType);
end
else
begin
li.ImageIndex := 1;
li.Caption := Msg.MessageParts.Items[idx].ContentType;
end;
end;
end;{*增加邮件的附件*}
procedure TForm1.SpeedButton1Click(Sender: TObject);
var
OpenDialog1:TOpenDialog;
begin
OpenDialog1:=TOpenDialog.Create(Nil);
if OpenDialog1.Execute then
begin
TIdAttachment.Create(Msg.MessageParts, OpenDialog1.FileName);
ResetAttachmentListView;
end;
OpenDialog1.Free;
end;
{*减少邮件的附件*}
procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
if Msg.MessageParts.Count>0 then
begin
Msg.MessageParts.Delete(lvFiles.Selected.Index);
ResetAttachmentlistView;
end;
end;end.