Hi Guys
I am new to Aspose, I want to fetch emails and save them without any attachments? How do I go about it.
I am able to fetch email but they are coming with the attachments, I want to do it separately.
Hi Guys
Hi Brian,
Thank you for using Aspose.Email.
You can use the following code sample that ignores fetching the message attachments. Setting the second flag of FetchMessage to “true” will ignore fetching message attachments. Please let us know if we can be of any additional help to you in this regard.
Sample Code:
ImapClient client = new ImapClient();
client.Host = "exchange.domain.com";
client.Username = "username";
client.Password = "password";
client.SelectFolder("Inbox");
ImapMessageInfoCollection coll = client.ListMessages();
foreach (ImapMessageInfo msgInfo in coll)
{
MailMessage msg = client.FetchMessage(msgInfo.SequenceNumber, true);
Console.WriteLine(msg.Attachments.Count);
msg.Save("a.eml", MailMessageSaveType.EmlFormat);
}
Hi Kashif
Hi Brian,
You can save the regular attachments from the fetched message as shown in the following code sample. Please note that signatures such as company logo etc. embedded in a message’s body are treated as LinkedResources whihc are different than regular attachments. Let us know if we can be of any additional help to you in this regard.
Sample Code:
ImapClient client = GetAsposeImapClient1();
client.SelectFolder("Inbox");
ImapMessageInfoCollection coll = client.ListMessages();
foreach (ImapMessageInfo msgInfo in coll)
{
MailMessage msg = client.FetchMessage(msgInfo.SequenceNumber);
Console.WriteLine(msg.Attachments.Count);
//Save message attachments to disc
foreach (Attachment att in msg.Attachments)
att.Save(att.Name);
}
Hi
Hi Brian,