This code will be help full i had developed and tested vb version only just converted this code to c#, so i will post the vb code for reference. it includes snippets for saving attachments to selected folder and also for save cc and bcc in CSV format to a string variable:
VB Code
Public Sub fetchMails()
Dim imapClient As New Imap4Client()
Dim mailNumber As Integer = 10
Dim notYetProcessedBox As Mailbox = imapClient.SelectMailbox("Inbox")
Dim msg As Message = notYetProcessedBox.Fetch.MessageObject(mailNumber)
Dim mailCC As String = ""
Dim mailBcc As String = ""
Dim cc() As ActiveUp.Net.Mail.Address = msg.Cc.ToArray()
Dim bcc() As ActiveUp.Net.Mail.Address = msg.Bcc.ToArray()
For Each address As ActiveUp.Net.Mail.Address In cc
mailCC &= address.ToString
Next
For Each address As ActiveUp.Net.Mail.Address In bcc
mailBcc &= address.ToString
Next
If msg.Attachments.Count <> 0 Then
If System.IO.Directory.Exists("../email_attachment/") = False Then
System.IO.Directory.CreateDirectory("../email_attachment/")
msg.Attachments.StoreToFolder("../email_attachment/")
End If
End If
End Sub
C# Code
public void fetchMails()
{
Imap4Client imapClient = new Imap4Client();
int mailNumber = 10;
Mailbox notYetProcessedBox = imapClient.SelectMailbox("Inbox");
Message msg = notYetProcessedBox.Fetch.MessageObject(mailNumber);
string mailCC = "";
string mailBcc = "";
ActiveUp.Net.Mail.Address[] cc = msg.Cc.ToArray();
ActiveUp.Net.Mail.Address[] bcc = msg.Bcc.ToArray();
foreach (ActiveUp.Net.Mail.Address address in cc) {
mailCC += address.ToString;
}
foreach (ActiveUp.Net.Mail.Address address in bcc) {
mailBcc += address.ToString;
}
if (msg.Attachments.Count != 0) {
if (System.IO.Directory.Exists("../email_attachment/") == false) {
System.IO.Directory.CreateDirectory("../email_attachment/");
msg.Attachments.StoreToFolder("../email_attachment/");
}
}
}