procedure TfmMail.SpeedButton2Click(Sender: TObject);
var
fmErrorDlg :TfmErrorDlg;
fmHintDlg :TfmHintDlg;
iId :integer;
begin
//检查输入框是否正确
//定义邮件信息
//连接SMTP服务器
//连接成功的话,发送邮件,并将邮件写入已发送邮件中
//断开SMTP服务器,提示已成功发送
if leToAddress.Text = '' then
begin
fmErrorDlg := TfmErrorDlg.Create(self);
fmErrorDlg.lMsg1.Caption := '';
fmErrorDlg.lMsg2.Caption := '收件箱地址必须填写,请';
fmErrorDlg.lMsg3.Caption := '查看...';
fmErrorDlg.ShowModal;
fmErrorDlg.Free;
leToAddress.SetFocus;
Exit;
end;
if leSubject.Text = '' then
begin
fmHintDlg := TfmHintDlg.Create(self);
fmHintDlg.lMsg1.Caption := '您将要发送的邮件尚无主题,您';
fmHintDlg.lMsg2.Caption := '确定要发送吗?单击[确定]发送';
fmHintDlg.lMsg3.Caption := '单击[取消]取消发送。';
fmHintDlg.ShowModal;
fmHintDlg.Free;
if not bIsOkButtonClicked then
begin
leSubject.SetFocus;
Exit;
end;
end;
adqTemp.Close;
adqTemp.SQL.Clear;
adqTemp.SQL.Add('select * from Mail where Default = 1');
adqTemp.Open;
if not adqTemp.Eof then
begin
IdSMTP1.Username := adqTemp.FieldByName('UserID').AsString;
IdSMTP1.Password := adqTemp.FieldByName('PassWord').AsString;
IdSMTP1.Host := adqTemp.FieldByName('SMTPAddress').AsString;
end;
IdSMTP1.Port := 25;
adqTemp.Close;
// IdMailMessage.ContentType := 'text/html';
// IdMailMessage.ContentTransferEncoding := 'binary' ;
IdMailMessage.From.Address := leFromAddress.Text;
IdMailMessage.From.Name := leFromMan.Text;
IdMailMessage.Subject := leSubject.Text;
IdMailMessage.Body.Assign(mBody.Lines);
IdMailMessage.Date := Now;
IdMailMessage.Recipients.EMailAddresses := leToAddress.Text;
// IdMailMessage.ContentType := 'text/plain';
// IdMailMessage.ContentTransferEncoding := '7bit';
try
try
IdSMTP1.Connect(1000);
IdSMTP1.AuthenticationType := atLogin;
IdSMTP1.Authenticate;
IdSMTP1.Send(IdMailMessage);
adqTemp.SQL.Clear;
adqTemp.SQL.Add('select * from sendedMail order by ID DESC');
adqTemp.Open;
if adqTemp.Eof then
iId := 0
else
iId := adqTemp.FieldByName('ID').AsInteger;
adqTemp.Close;
IdMailMessage.SaveToFile(sAppPath + 'Mail/Sended/' + leToAddress.Text+IntToStr(iId + 1)+'.eml',false);
adqMail.Close;
adqMail.SQL.Clear;
adqMail.SQL.Add('select * from SendedMail');
adqMail.Open;
adqMail.Append;
adqMail.FieldByName('ID').AsInteger := iId + 1;
adqMail.FieldByName('FileName').AsString := leToAddress.Text+IntToStr(iId + 1)+'.eml';
adqMail.FieldByName('Date').AsString := FormatDateTime('YYYY-MM-DD',Now);
adqMail.Post;
except on E:Exception do
sbStatus.Panels[1].Text:= '邮件发送失败';
end;
finally
if IdSMTP1.Connected then IdSMTP1.Disconnect;
lbAnnex.Clear;
end;