Author |
|
yanzhenbest Newbie
Joined: 19 May 2015
Online Status: Offline Posts: 8
|
Posted: 19 May 2015 at 1:31am | IP Logged
|
|
|
how to download the bodyhtmltext without downloading the attachment first?
|
Back to Top |
|
|
Igor AfterLogic Support
Joined: 24 June 2008 Location: United States
Online Status: Offline Posts: 6104
|
Posted: 19 May 2015 at 4:26am | IP Logged
|
|
|
The simplest way to do that is with Imap.DownloadEnvelopes method, make sure parts includes MessagePreview flag, and set bodyPreviewSize to number of bytes of message body to be downloaded. If you set it to 10K for example, that will be sufficient for most text bodies out there, some tiny attachments might get through as well, but big attachments will not pass.
The other way is highly advanced, it requires manipulating IMAP BodyStructure of the message and dealing with all the body parts separately - it might be especially useful when message includes, for example, 2 HTML parts. You can find an example of working with BodyStructure here.
--
Regards,
Igor, AfterLogic Support
|
Back to Top |
|
|
yanzhenbest Newbie
Joined: 19 May 2015
Online Status: Offline Posts: 8
|
Posted: 19 May 2015 at 7:45am | IP Logged
|
|
|
Thank you for your reply.
1."The simplest way to do that is with Imap.DownloadEnvelopes method, make sure parts includes MessagePreview flag, and set bodyPreviewSize to number of bytes of message body to be downloaded. If you set it to 10K for example, that will be sufficient for most text bodies out there, some tiny attachments might get through as well, but big attachments will not pass. "
//This way code is this?
string uid = "10";
EnvelopeCollection _envs = imp.DownloadEnvelopes(uid, true, EnvelopeParts.MessagePreview, 10240); // 10k is 10240 or 10?
----------------My test:DownloadEnvelopes---------------------
string uid="10"; //email size:15476646
DateTime _d1 = DateTime.Now;
EnvelopeCollection _envs = imp.DownloadEnvelopes(uid, true, EnvelopeParts.MessagePreview, 10240);
DateTime _d2 = DateTime.Now;
double _i1 = _d2.Subtract(_d1).TotalSeconds;
//the Result
_i1 = 32.5989626;
----------------My test:DownloadEntireMessage---------------------
string uid="10"; //email size:15476646
DateTime _d1 = DateTime.Now;
MailMessage _msg = imp.DownloadEntireMessage(long.Parse(uid), true);
DateTime _d2 = DateTime.Now;
double _i1 = _d2.Subtract(_d1).TotalSeconds;
//the Result
_i1 = 30.5783129;
---------------------------------------------------------------------
Time spent almost two approaches.
2:"The other way is highly advanced, it requires manipulating IMAP BodyStructure of the message and dealing with all the body parts separately - it might be especially useful when message includes, for example, 2 HTML parts. You can find an example of working with BodyStructure here. "
//This way code is this?
string uid = "10";
EnvelopeCollection _envs = imp.DownloadEnvelopes(uid, true, EnvelopeParts.BodyStructure, 0);
I need email bodyhtmltext, But i can't get bodyhtmltext use this way.
---------------------------------------------------------------------
The method i need to quickly get the email bodyhtmltext.
|
Back to Top |
|
|
Igor AfterLogic Support
Joined: 24 June 2008 Location: United States
Online Status: Offline Posts: 6104
|
Posted: 19 May 2015 at 8:57am | IP Logged
|
|
|
First of all, it's not clear why the operation takes THAT long in either of the cases - and not really possible to determine that without the logs. One guess is the server might disregard message preview size (which is set in bytes) and returns the entire message; in terms of IMAP protocol, it works as asking server to return at least that number of bytes and some servers ignore that. But if the value is not discarded, you might need to fine-tune the number of bytes specified as it could be insufficient for dealing with large amount of HTML in there.
As for the 2nd approach, it's indeed a highly-advanced one, the code you posted will only return an overview on body structure, you would need to iterate through it to detect and download the content type you're looking for.
To summarize, there's no simple way to get just the HTML body. You can download entire message (the most trouble-free option), get first N bytes of a message body (doesn't work with all the IMAP servers out there) or deal with envelopes (takes a lot of work and tweaking).
--
Regards,
Igor, AfterLogic Support
|
Back to Top |
|
|