We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Body of an attachment

How do you extract the body of an attachment?

Here’s the code:

foreach (Attachment attachment in Email.Attachments)

What property contains the body (text) of the attachment?

Also, I noticed the From Property is a collection.
It’s possible to have multiple Froms?

Hi Joel,

Thank you for contacting Aspose Support team.

You can access the content stream of the attachment and then read it into a buffer or save to disc. However, there is no direct property that can give you the text of a text attachment in a message.

Can you please point us to where you found the Form Property as a collection? From property is assumed to contain a single address.

Thank you for your response.

I kind of figured so.
Do you have any code examples?

RE: Ftom property:
It's defined as MailAddress - which handles miltiple instances

Below Code:

MailMessage poEmail = client.FetchMessage(i);
.
.
.
string psFrom = poEmail.From[0].ToString();

Again Thank you...

Never mind - I figured a way.

Don’t take this a criticism - because it’s not.
To say I happy with your dll is an understatement.

However, in the old dll (which had many problems)
They had a quick method that sucked in the whole text.
Instead of having save and read and delete.

BUT AGAIN:
I’M VERY PLEASED SO FAR.

Hi Joel,


Thank you for the feedback.

Following sample code can be used to fetch the attachment body. Please give it a try and let us know the feedback.

MailMessage msg = MailMessage.Load(“Sample.msg”);<o:p></o:p>

Attachment att = msg.Attachments[0];

using (var reader = new StreamReader(att.ContentStream, Encoding.UTF8))

{

var content = reader.ReadToEnd();

File.WriteAllText("AttachmentText.txt", content);

}