Display an icon for emails with one or multiple attachments

Hi,

We are using Aspose.Network 6.7.0.0.

We are getting the email through imap server and we are populating a GridView.

We are not able to show 2 different icons when we have an attachment for an email.

how can we do to have the following :

Column 1 Column 2 Column 3

Attachment icon email icon email subject .....

(paperclip) (envoloppe) (string)

Thanks in advance for your help

Fady Sayegh

Hi Fady,

Please use the below method to check whether a message is an appointment or not.

private bool IsAppointment(MailMessage msg)
{
// return true if it is an appointment
if (msg.Headers[“content-type”].Contains(“text/calendar”) == true)
return true;

// check each alternate view in case of multipart message
if (msg.Headers[“content-type”].Contains(“multipart/alternative”) == true)
{
// check in alternate views
foreach (AlternateView view in msg.AlternateViews)
{
if (view.ContentType.ToString().Contains(“text/calendar”) == true)
return true;
}
}

return false;
}

Hi Saqib,

Thanks for your answer.

When i bind my grid, i'm making it with ImapMessageInfo.

So in my RowBound event i'm not getting a MailMessage object.

Please find below my snippet code :

protected void grdMailList_RowBound(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

ImapMessageInfo objMessage = (ImapMessageInfo)e.Row.DataItem;

if (objMessage.IsRead == true)

{

Image imgMailType = (Image)e.Row.Cells[1].FindControl("imgMailType");

imgMailType.ImageUrl = "~/App_Themes/Images/Email_Read.gif";

}

else

e.Row.Font.Bold = true;

}

How can do to make your solution above work in my code without reading the entire message because it will take a lot of time to fill the grid?

One more question please : how can i display a column with an icon (paperclip) to indicates to the user that a mail contain an attachment?

Thanks in advance for your answer

Fady Sayegh

Hello Fady,

I am sorry, it is not currently possible with ImapMessageInfo class, you need to download the message to get this information.

However, we will further look into these scenarios and will add the required features, if feasible.

  • Issue 30365: Differentiate between message and attachment using ImapMessageInfo
  • Issue 30366: Add a property in ImapMessageInfo to check if email has any attachment(s)

Hi,

We cannot fetch the header information using the Imap protocol. But with Aspose.Email 1.1, it is possible now to fetch incomplete message from Imap server and then call the above method to know whether it contains attachments.

ImapMessageInfoCollection messages = client.ListMessages();

foreach (ImapMessageInfo messageInfo in messages)
{
MailMessage mailMessage = client.FetchMessage(messageInfo.SequenceNumber, true); // true: get incomplete message
bool hasAttachment = mailMessage.Attachment.Count > 0;
}

The issues you have found earlier (filed as 30366 ;30365 ) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.