我使用以下(简化)代码在我的Delphi 5命令行应用程序中发送电子邮件:
Smtp := TIdSmtp.Create (nil);
Smtp.Host := 'smtp.office365.com';
smtp.Port := 587;
Smtp.UserName := 'info@aaaaaa.com';
Smtp.Password := '********';
Smtp.AuthType := satDefault;
Smtp.UseTLS := utUseExplicitTLS;
HandlerSocket := TIdSSLIOHandlerSocketOpenSSL.Create(Smtp);
HandlerSocket.SSLOptions.Method := sslvTLSv1;
HandlerSocket.PassThrough := False;
Smtp.IOHandler := HandlerSocket;
//Create message in helper object
SmtpWrapper.Sender := 'o@aaaaaa.com';
SmtpWrapper.Recipients := adminAddresses;
SmtpWrapper.ReplyToName := 'm@x-net.com';
SmtpWrapper.Body := 'Invalid Keys in order: ' + #13#10;
SmtpWrapper.Subject := ' OrderNo';
TRY
Smtp.Connect;
try
if not Smtp.Authenticate then
raise Exception.Create ('SMTP Authentification Error');
Smtp.Send (SmtpWrapper.IdMsg);
finally
Smtp.Disconnect;
end;
EXCEPT
ON E : exception DO BEGIN
ShowMessage ('Elmar Exception: ' + E.message);
END;
END;
当SMTP服务器没有返回错误时,一切顺利。 但是,当出现错误时,将从TIdReplySMTP.RaiseReplyError引发异常。 在TIdSMTPBase.SendNoPipelining中捕获并重新抛出异常。 在该位置,我的应用程序因应用程序定义的异常而停止。
有没有人经历过这个?
我使用的是Delphi 5,Indy 10.6.2和OpenSSL 1.0.2f。
谢谢你的期待。