0 votes
by (750 points)

Below is the code for saving the pdf attachment but I am not able to open the pdf??? please answer my question as soon as possible

string strTemp = "D:\RahulTemp\";
ImapMessageCollection lst = imap.Search(ImapSearchParameter.Not(ImapSearchParameter.Deleted));
foreach (var val in lst)
{
MailMessage mm = new MailMessage();
mm = imap.GetMailMessage(val.UniqueId);
MailMessage mm2 = new MailMessage();
AttachmentCollection attcol = mm.Attachments;

                for (int i = 0; i < attcol.Count; i++)
                {
                    //if (attcol[i].FileName.Trim().EndsWith(".pdf") || attcol[i].FileName.Trim().EndsWith(".htm") || attcol[i].FileName.Trim().EndsWith(".html") || attcol[i].FileName.Trim().EndsWith(".doc") || attcol[i].FileName.Trim().EndsWith(".xls") || attcol[i].FileName.Trim().EndsWith(".xlsx") || attcol[i].FileName.Trim().EndsWith(".bmp"))
                    //{
                    //MimeEntity me = attcol[i].ToMimeEntity();
                    //me.Save(strTemp + me.ContentDisposition.FileName);
                    if (attcol[i].FileName.Contains(":"))
                    {
                        mm.Save(strTemp + attcol[i].FileName.Replace(":", "_")); //attcol[i].FileName
                        mm2.Attachments.Add(new Attachment(strTemp + attcol[i].FileName.Replace(":", "_")));
                    }
                    else
                    {
                        mm.Save(strTemp + attcol[i].FileName); //attcol[i].FileName
                        mm2.Attachments.Add(new Attachment(strTemp + attcol[i].FileName));
                    }
                    string str = mm.BodyText;
                    //}
                }
                imap.CopyMessage(val.UniqueId, "Archive");
Applies to: Rebex Secure Mail

1 Answer

0 votes
by (58.9k points)
edited by

Would it be possible to zip the original email with the problematic pdf attachment and send the zip archive to support@rebex.net along with the version of Rebex components that you are using?

It will enable us to check whether it is a problem with the component or with the email itself.

We treat mails with pdf attachments the same as any other email attachments. The following code will save the first attachment from a mail message:

MailMessage mm = new MailMessage();
mm = imap.GetMailMessage(val.UniqueId);

mm.Attachments[0].Save(@"C:\temp\attachment.pdf");
...