Download attachment

Apr 26, 2015 at 9:09 PM
I want to download attachment from my email using c# code. i am using your library but it is not helping me in downloading the attachment or embedded resource.

if (_selectedMessage.Attachments.Any())
        {
            string tmpDir = Path.Combine(Application.StartupPath, "tmp");
            string msgTmpDir = Path.Combine(tmpDir, _selectedMessage.UId.ToString(CultureInfo.InvariantCulture));

            if (!Directory.Exists(msgTmpDir))
                Directory.CreateDirectory(msgTmpDir);

            var files = new List<string>();

            foreach (Attachment file in _selectedMessage.Attachments)
            {
                string path = Path.Combine(msgTmpDir, file.FileName);
                if (!File.Exists(path))
                    File.Create(path);

                files.Add(path);
                file.Download(); 

                file.Save(path, file.FileName);
            }

            UpdateAttachmentIcons(files);

            lsvAttachments.Items.AddRange(_selectedMessage.Attachments.Select(file =>
                new ListViewItem(string.Format("{0} ({1})", file.FileName,
                    file.Downloaded ? FormatFileSize(file.FileSize) : "..."))
                {
                    ImageKey = file.FileName.Split('.').Last()
                }).ToArray());


        }