发送也没问题了,但是出现了新的问题,就是不能重复发送,也就是当发送一次后,修改一下内容(比如主题、信件内容、或者收件人之类的)之后再点击发送按钮,就出错了
出错信息是:
Access violation at address 0046BC81 in module
程序主体如下:
IdMessage1.Clear;
IdMessage1.Body.Assign(Contents.Lines); //Text
IdMessage1.From.Text := SenderAddress.Text; //Address
IdMessage1.Recipients.EMailAddresses := ReceiverAddress.Text;
IdMessage1.Subject := Title.Text;
//IdMessage1.ContentType := 'Text';
IdSMTP1.AuthenticationType := atLogin;
IdSMTP1.Username := SenderName.Text;
IdSMTP1.Password := Password.Text;
IdSMTP1.Host := HostName.Text;
IdSMTP1.Port := 25;
try
try
StatusBar1.SimpleText := 'Connecting...';
StatusBar1.Update;
IdSMTP1.Connect;
except
MessageBox(0, '连接服务器失败', nil, MB_OK or MB_ICONERROR);
StatusBar1.SimpleText := 'Connect Failed';
StatusBar1.Update;
Exit;
end;
StatusBar1.SimpleText := 'Connected';
StatusBar1.Update;
try
StatusBar1.SimpleText := 'Sending...';
StatusBar1.Update;
IdSMTP1.Send(IdMessage1);
StatusBar1.SimpleText := 'Send Successed';
StatusBar1.Update;
MessageBox(0, '邮件已经发送成功', nil, MB_OK or MB_ICONINFORMATION);
except
StatusBar1.SimpleText := 'Send Failed';
StatusBar1.Update;
MessageBox(0, '邮件发送失败', nil, MB_OK or MB_ICONERROR);
end;
finally
IdMessage1.Free;
IdSmtp1.Free;
end;
请高手赐教啊