Need Delphi 6示例,用于在TIdSmtp发送操作期间更新进度条,尤其是对于大型附件 [英] Need Delphi 6 example for updating a progress bar during TIdSmtp send operation, especially for large attachments

查看:64
本文介绍了Need Delphi 6示例,用于在TIdSmtp发送操作期间更新进度条,尤其是对于大型附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Indy TIdSmtp组件发送电子邮件。我发送的电子邮件会有一个很大的附件,通常在5到40 MB之间。我想更新一个进度条,该进度条将显示发送的总体进度占需要发送的字节总数的百分比。我不在乎它是否真的很精确,足以让有人看着进度条指示整个电子邮件发送过程有多远。

I am using the Indy TIdSmtp component to send E-mails. The E-mails I am sending will have a large attachment, usually in the range of 5 to 40 MB. I want to update a progress bar that will show the overall progress of the send as a percentage of the total number of bytes that need to be sent. I don't care if it's really precise, just good enough to give someone watching the progress bar an indication for how far along the overall E-mail sending process is.

有人可以指出我的代码示例向我展示如何执行此操作吗?

Can someone point me to a code sample that shows me how to do this?

推荐答案

TIdSMTP 在将电子邮件发送到服务器时对其进行实时编码。提前不知道要发送的字节总数。您甚至可以确定一个值,即使合理接近的唯一方法是通过 TIdMessage.SaveToStream()<>将电子邮件编码为临时的 TStream / code>方法,然后获取 TStream.Size 属性的值。由于您正在编码大型附件,因此将花费一些时间和大量的内存开销。由于 TIdSMTP 只会在传输过程中再次重新编码电子邮件,因此无法保证实际传输的字节数将与临时 TStream.Size相匹配。 由于各种电子邮件标头的动态性质,例如时间戳和MIME边界。

TIdSMTP encodes the email on-the-fly as it is being sent to the server. The total number of bytes being sent is not known ahead of time. The only way you would be able to determine a value even reasonably close is to encode the email to a temporary TStream via the TIdMessage.SaveToStream() method and then grab the value of the TStream.Size property. Since you are encoding large attachments, that will take some time and lots of memory overhead. Since TIdSMTP will just re-encode the email again during transmission, there is no guarantee that the number of bytes actually transmitted will match the temp TStream.Size due to the dynamic nature of various email headers, such as timestamps and MIME boundaries.

要确定实际发送了多少字节,请使用 TIdSMTP.OnWork ... 事件,其中 AWorkMode 参数将设置为 wmWrite 。由于 TIdSMTP.Send()事先不知道它将发送多少字节,因此 AWorkCountMax 参数 TIdSMTP.OnWorkBegin 事件将为 0 ,但是至少您会知道实际的电子邮件数据何时开始编码/发送(在 TIdSMTP 与服务器交换了几个命令之后)。 TIdSMTP.OnWork 事件的 AWorkCount 参数将是实际发送的字节总数。触发 TIdSMTP.OnWorkEnd 事件时,电子邮件已完成发送。

To determine how many bytes are actually being sent, use the TIdSMTP.OnWork... events, where the AWorkMode parameter will be set to wmWrite. Since TIdSMTP.Send() does not know ahead of time how many bytes it will be sending, the AWorkCountMax parameter of the TIdSMTP.OnWorkBegin event will be 0, but at least you will know when the actual email data begin encoding/sending (after TIdSMTP has exchanged several commands with the server). The AWorkCount parameter of the TIdSMTP.OnWork event will be the total number of bytes actually sent. When the TIdSMTP.OnWorkEnd event is fired, the email has finished being sent.

基于temp TStream.Size 属性和 TIdSMTP.OnWork AWorkCount 参数事件,您将能够显示进度条的百分比近似值。不能保证它是100%准确的,但是会很接近。

Based on the temp TStream.Size property and the AWorkCount parameter of the TIdSMTP.OnWork event, you will be able to display an approximation of a percentage for a progress bar. It will not be guaranteed to be 100% accurate, but it will be close.

这篇关于Need Delphi 6示例,用于在TIdSmtp发送操作期间更新进度条,尤其是对于大型附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆