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

Free Support Forum - aspose.com

How to remove the body content from outlook mail

Hi sir,



I have one mail, in this mail we have two attachment and message content, for now i want to remove the message content and save only attachment for further process. pls help me asap.

he message as attachments are saved separately to disc. Please have a look at the following code sample and our documentation section, Working with Attachments, for your kind reference and let

Sample Code:

// Create an instance of MailMessage and load an email file

MailMessage mailMsg = MailMessage.Load(dataDir + “Message.msg”, new MsgLoadOptions());

foreach (Attachment attachment in mailMsg.Attachments)

{

// To display the the attachment file name

attachment.Save(dataDir + “MessageEmbedded_out.msg”);

Console.WriteLine(attachment.Name);

}

Hi



Thanks for sending the reply. I need the save the email with out email message.

Hi Senthil,


I am afraid that I could not understand the above reply. Could you please explain it in more detail if issue is not resolved yet?

Hi kashif,


I have one outlook mail which contain mail body content and two attachment. Now i want save the mail with two attachment and no need mail body content.


Note:

I remove the body content of mail

Hi Kashif,



Just to further clarify. I would like to save the only the attachments without the email content. Hope this clarifies my request. Thank You.

Hi Senthil,


You can clear the body of a message by setting the html body of a message to empty string as shown in the code sample below. It works for both text and well as html emails. Please try it at your end and let us know your feedback.

Sample Code:

MailMessage eml = MailMessage.Load(“email.msg”, new MsgLoadOptions());

eml.HtmlBody = string.Empty;

eml.Save(“emlWithoutBody.eml”, Aspose.Email.Mail.SaveOptions.DefaultEml);
Hi Kashif,

I put the code

Dim eml As MailMessage = MailMessage.Load("email.msg", New MsgLoadOptions())

eml.HtmlBody = String.Empty

eml.Save("emlWithoutBody.eml", Aspose.Email.Mail.SaveOptions.DefaultEml)

the error will occur in this MsgLoadOptions() in this word "type MsgLoadoptions() is not definied"

and
Aspose.Email.Mail.SaveOptions "save option is not member of email"

Hi Senthil,


Please use the latest version of the API at your end. You also need to resolve the dependencies for these by including the using statements for MsgLoadOptions and SaveOptions which reside in Aspose.Email.Mail namespace. Please try these at your end and if you face any issue, share a sample console application with us for further assistance from our end.

Hi Kashif,



I update by my aspose.email.dll and execute the code that u send.

Dim eml As MailMessage = MailMessage.Load(spathdel, New MsgLoadOptions())

eml.HtmlBody = String.Empty

eml.Save(spathdel, Aspose.Email.Mail.SaveOptions.DefaultEml)

but the mail save with email content i upload pdf image


email content: pls see the attachment

Hi Senthil,


I have tried the above code using sample MSG files with attachments and body. It is observed that it creates EML file without the body content. Could you please share your sample MSG file with us for testing here? It will help us to re-produce the issue and provide assistance accordingly.

Hi Kashif,


I send the Msg file for testing.

Hi Senthil,


While converting to MHTML, the API first considers HtmlBody flag for inclusion in output. If this is empty, then Body property is used. In this case, you also need to set the MailMessage.Body property to String.Empty for empty MHTML output.

Hi Kashif



I cannot understand that u say, pls explain that briefly for the sample msg file that i send.

Hi kashif



Sorry I cannot understand that u say, pls briefly explain that with my sample msg file that i send.

Hi Senthil,


Please set both MailMessage.HtmlBody and MailMessage.Body properties to Empty string for getting empty contents in the message’s output. Please let us know if you need any further information in this regard.