L
lczh8420
Unregistered / Unconfirmed
GUEST, unregistred user!
大家看看下面的一段代码:为什么老是出错呢?
type
IdSMTP: TIdSMTP;
IdMsgSend: TIdMessage;
mmContent: TMemo;
edtTo: TEdit;
edtSubject: TEdit;
edtFrom: TEdit;
edtSrvPw: TEdit;
edtSrvUser: TEdit;
procedure TEmailForm.Button1Click(Sender: TObject);
begin
{ 根据用户所填写的内容创建邮件 }
with IdMsgSend do
begin
Body.Assign(mmContent.Lines); //邮件正文
From.Text := edtFrom.Text; //邮箱名称
Subject := edtSubject.Text; //邮件主题
From.Address := Trim(edtFrom.Text); //发件人地址
Recipients.EMailAddresses := Trim(edtTo.Text); //收件人地址
Priority := mpNormal; { Message Priority }
IdMsgSend.ContentType:= 'text/plain';
CCList.EMailAddresses := edtTo.Text; {CC}
BccList.EMailAddresses := edtTo.Text; {BBC}
end;
{ 发送邮件 }
with IdSMTP do
begin
Host := 'mx.mail.163.com'; // 将Host赋值为目的地
Port := 25; // smtp服务默认的端口为25
IdSMTP.AuthenticationType := atNone;
Username := edtSrvUser.Text;
Password := edtSrvPw.Text;
try
Connect; //连接到服务器
Send(IdMsgSend); //发送刚才创建的邮件
ShowMessage('发送完毕'); //发送完毕后提示
finally
Disconnect; //断开服务器连接
end;
end;
end;
type
IdSMTP: TIdSMTP;
IdMsgSend: TIdMessage;
mmContent: TMemo;
edtTo: TEdit;
edtSubject: TEdit;
edtFrom: TEdit;
edtSrvPw: TEdit;
edtSrvUser: TEdit;
procedure TEmailForm.Button1Click(Sender: TObject);
begin
{ 根据用户所填写的内容创建邮件 }
with IdMsgSend do
begin
Body.Assign(mmContent.Lines); //邮件正文
From.Text := edtFrom.Text; //邮箱名称
Subject := edtSubject.Text; //邮件主题
From.Address := Trim(edtFrom.Text); //发件人地址
Recipients.EMailAddresses := Trim(edtTo.Text); //收件人地址
Priority := mpNormal; { Message Priority }
IdMsgSend.ContentType:= 'text/plain';
CCList.EMailAddresses := edtTo.Text; {CC}
BccList.EMailAddresses := edtTo.Text; {BBC}
end;
{ 发送邮件 }
with IdSMTP do
begin
Host := 'mx.mail.163.com'; // 将Host赋值为目的地
Port := 25; // smtp服务默认的端口为25
IdSMTP.AuthenticationType := atNone;
Username := edtSrvUser.Text;
Password := edtSrvPw.Text;
try
Connect; //连接到服务器
Send(IdMsgSend); //发送刚才创建的邮件
ShowMessage('发送完毕'); //发送完毕后提示
finally
Disconnect; //断开服务器连接
end;
end;
end;