When copying an mail from the personal folder to a Public folder, you may receive “There is no replica for that mailbox on this server.” error.
This error is generated by Exchange server and unfortunately this is the Exchange limitation. Here’s Microsoft’s response to this problem:
Copying from user mailboxes to public folders does not work with Exchange IMAP4.
Your users need to copy the message to a personal folder and then back up to the public folder (append) or forward it to an address that gets archived to a public folder.
Workaround
It seems the only way to workaround this is by downloading a message and uploading it to public folder. Important thing is that you don’t need to parse email message at all – you just download and upload raw eml data. Please also note that public folder may be in fact stored on a another IMAP server instance (different server address) – this is usually indicated during logon with REFERRAL error.
// C#
using(Imap imap = new Imap())
{
imap.Connect("imap.example.com"); // or ConnectSSL for SSL
imap.UseBestLogin("user", "password");
imap.SelectInbox();
List<long> uids = imap.Search(Flag.All);
foreach (long uid in uids)
{
string eml = imap.GetMessageByUID(uid);
IMail email = new MailBuilder().CreateFromEml(eml);
if (email.Subject.Contains("[REF"))
UploadToPublic(eml);
}
imap.Close();
}
' VB.NET
Using imap As New Imap()
imap.Connect("imap.example.com") ' or ConnectSSL for SSL
imap.UseBestLogin("user", "password")
imap.SelectInbox()
Dim uids As List(Of Long) = imap.Search(Flag.All)
For Each uid As Long In uids
Dim eml As String = imap.GetMessageByUID(uid)
Dim email As IMail = New MailBuilder().CreateFromEml(eml)
If email.Subject.Contains("[REF") Then
UploadToPublic(eml)
End If
Next
imap.Close()
End Using
Here is the body of UploadToPublic method:
// C# code
private void UploadToPublic(string eml)
{
using (Imap imap = new Imap())
{
imap.Connect("server"); // or ConnectSSL for SSL
imap.Login("user", "password");
imap.UploadMessage("#Public/Cases", eml);
imap.Close();
}
}
' VB.NET code
Private Sub UploadToPublic(eml As String)
Using imap As New Imap()
imap.Connect("server")
' or ConnectSSL for SSL
imap.Login("user", "password")
imap.UploadMessage("#Public/Cases", eml)
imap.Close()
End Using
End Sub