This project is read-only.

Adding a letter into the folder

Topics: Help requests
Jan 18, 2016 at 7:38 PM
How can i add a letter into the folder(Sent,for example).I wrote code,looking just like this snippet 'imapClient.Folder.Sent.AppendMessage(message);',but the folder was still empty.
Jan 19, 2016 at 10:20 PM
Looking into the source code for AppendMessage(), it appears that the logic is broken if the message contains non-ascii text in the 8bit encoding (it should work fine if the 8bit text is base64 or quoted-printable encoded) or if the message has raw 8bit text in the headers because it will incorrectly calculate the length of the literal that it will be sending in the APPEND command.

I'm not sure if this is the issue you are having or not.

This doesn't appear to be a trivial bug to fix because each mime part of the message could potentially be defined to use a different charset so the code can't simply be fixed to use Encoding.UTF8.GetBytes() to get a proper byte-count.

I would expect you to get an exception in that case, though, rather than no errors at all.

To rule out the possibility of a server bug, maybe you could try using my MailKit library to write a quick sample test to see if that works.
using (var client = new ImapClient (new ProtocolLogger ("imap.log"))) {
    client.Connect (hostName, port, useSsl);
    client.Authenticate (userName, password);

    IMailFolder sent;
    if (client.Capabilities.HasFlag (ImapCapabilities.XList) || client.Capabilities.HasFlag (ImapCapabilities.SpecialUse)) {
        // the IMAP server can tell us which folder is the Sent folder
        sent = client.GetFolder (SpecialFolder.Sent);
    } else {
        // the IMAP server has no idea which folder is the Sent folder, it is client-specific
        var personal = client.GetFolder (client.PersonalNamespaces[0]);
        sent = personal.GetSubfolder ("Sent Mail"); // or whatever the name of the folder is on your server

    sent.Append (message);

    client.Disconnect (true);
If that doesn't work, you'll be able to look at the imap.log file to see exactly what commands were sent to the IMAP server and hopefully use that to figure out the problem (or email me and I can take a look at it).

Hopefully that helps.