Comments (6)
Yea, the SpecialFolders API will return null for folders that are not defined by the server via the SPECIAL-USE or XLIST extensions (SPECIAL-USE is an official IMAP extension and XLIST is a custom extension that Google uses for GMail).
Exchange probably doesn't implement either extension, so that's probably why it returns null.
What you'll probably need to do is have a configuration setting in your app allowing the user to specify what the name of their "Sent" folder is.
Some mail clients, like Outlook, auto-create a folder on the server called "Sent Mail". Others create "sent-mail", and some just call it "Sent". And some clients create a folder with a translated name.
This is actually why, I think, developers came up with the SPECIAL-USE IMAP extension because it makes things a lot simpler.
One way to check if the IMAP server supports SPECIAL-USE is to check:
if ((client.Capabilities & (ImapCapabilities.SpecilUse | ImapCapabilities.XList)) != 0) {
// ...
}
Does that help?
from mailkit.
Well, it explains the situation, but I remember ImapX did have Sent folder (probably implementation not according to standards I guess?) when I used it with the same Exchange. Nevertheless, what would be the best approach - i'm trying to list all root folders and check for "Sent" names, but probably doing something wrong as
var root = client.GetFolder("");
returns folder that cannot be opened (BAD response). How do I correctly list all root-level folders? From there on I can recursively traverse via GetSubfolders, that works nicely already.
Thanks,
Tomas
from mailkit.
OK, just tried Sent fallback to Sent Items and Odeslaná Pošta (local version) , last one worked, so solved I guess. Thank you,
Tomas
from mailkit.
I'm glad you figured it out, but I guess I should give my recommendation anyway, just in case anyone else stumbles onto this sort of problem (and I'll probably try to document it as well).
My recommendation would be to do something like this:
static string[] CommonSentFolderNames = { "Sent Items", "Sent Mail", /* maybe add some translated names */ };
static IFolder GetSentFolder (ImapClient client, CancellationToken cancellationToken)
{
var personal = client.GetFolder (client.PersonalNamespaces[0]);
foreach (var folder in personal.GetSubfolders (false, cancellationToken)) {
foreach (var name in CommonSentFolderNames) {
if (folder.Name == commonName)
return folder;
}
}
return null;
}
I guess this could be done simpler with LINQ:
var personal = client.GetFolder (client.PersonalNamespaces[0]);
var sentFolder = personal.GetSubfolders (false).FirstOrDefault (x => CommonSentFolderNames.Contains (x.Name));
from mailkit.
yep, done exactly as you suggested Jeff. I think this can be closed now, or?
Thank you for your help,
Tomas
from mailkit.
Yea, I just left it open until I had time to add the above snippets to the documentation.
from mailkit.
Related Issues (20)
- Question: How to edit attachments in the IEnumerable<MimeEntity> Attachments property of message object? HOT 13
- https://Mimekit.net certificate expired and site is extremely slow HOT 4
- System.Net.Sockets.SocketException (10060) HOT 2
- System.ArgumentNullException throwed on NTLM authentication HOT 3
- Please, could you provide examples for using ProxyClient, also how/when to use Sockets? HOT 1
- Syntax error in MODSEQ. Unexpected atom token: -1 HOT 6
- Implement the IMAP PARTIAL extension
- failed to run on android HOT 6
- Strange memory problem after calling IMailFolder.IsOpen HOT 1
- Error when invoking Authenticate multiple times over the same connection HOT 1
- Done token won't cancel IMap IdleAsync HOT 10
- Syntax error in BODYSTRUCTURE. Unexpected token: '(' HOT 4
- `.Inbox` returning null HOT 10
- Sending MimeMessage using Mircosoft Graph HOT 1
- SocketException (995): The I/O operation has been aborted because of either a thread exit or an application request. HOT 4
- Recommendations for fatching and processing large amounts of emails HOT 1
- [Yandex] GetBodyPart() throws `Syntax error in BODY. Unexpected token: ')'` for MimeParts with empty content HOT 3
- Iterating through attachments does not provide a name for the attachment HOT 2
- Authentication on SMTP to Microsoft Outlook using OAuth HOT 1
- MimeMessage.TextBody not returning body HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mailkit.