简体   繁体   中英

progress bar with apache common email

I am using apache common email library to send email , as follow

// Create the attachment
   EmailAttachment attachment = new EmailAttachment();
   attachment.setPath("mypictures/john.jpg");
   attachment.setDisposition(EmailAttachment.ATTACHMENT);
   attachment.setDescription("Picture of John");
   attachment.setName("John");

// Create the email message
   MultiPartEmail email = new MultiPartEmail();
   email.setHostName("mail.myserver.com");
   email.addTo("jdoe@somewhere.org", "John Doe");
   email.setFrom("me@apache.org", "Me");
   email.setSubject("The picture");
   email.setMsg("Here is the picture you wanted");

// add the attachment
   email.attach(attachment);

// send the email
   email.send();

I want to show progress bar until attached the file and send..

How can we do?

I don't see any way you can have a callback from commons-email which let's you know how much of the data is already transformed, so unless you hack into apache commons email itself you won't get notified from the library itself.

The only other way I see to "emulate" this is to build in some knowledge about how long a transfer usually takes, ie how many bytes you usually transfer per second and use this for a progress dialog display. But naturally this may lead to inaccurate information in the progress bar if transfer speed varies a lot over time or the application is used with different network connection types.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM