Closed alasdair-richardson closed 3 months ago
Sorry trying to work out how to label as a question
Actually just saw the wiji section on folders, looks like maybe this would work - If I update to a later version than 2.10.0. Would that be correct?
var mailFolder = await _imapReceiver.MailFolderClient.GetFolderAsync([mailFolderName], cancellationToken);
Yes, try the second method and let me know how it goes 🙂
Will do. I just tried the method suggested on that wiki page for 2.10.0 (Option 5, GetOrCreateFolderAsync) and it did not work. Had to fix the example code - do you want me to do that on the wiki? (missing var, no return)
If you can edit it, please do! If not then post it here and I'll update it.
Oh ok i don't think I can edit so here
public async Task<IMailFolder> GetOrCreateFolderAsync(string mailFolderName, CancellationToken cancellationToken = default)
{
var client = _imapReceiver.ImapClient;
var baseFolder = client.GetFolder(client.PersonalNamespaces[0]);
var folder = baseFolder.GetSubfolders(false, CancellationToken.None).FirstOrDefault(x =>
mailFolderName.Equals(x.Name, StringComparison.OrdinalIgnoreCase));
try
{
folder ??= await client.GetFolderAsync(mailFolderName, cancellationToken).ConfigureAwait(false);
}
catch (FolderNotFoundException)
{
folder = await baseFolder.CreateAsync(mailFolderName, isMessageFolder: true, cancellationToken);
}
return folder;
}
-- added var before folder and a return at the bottom
Thanks! I actually made multiple mistakes with that one as I didn't test it properly, I'll add a tested method here as that folder still won't be open sorry.
If you download the pre-release from NuGet you can use this: var folder = await mailFolderClient.GetOrCreateFolderAsync(destinationFolderFullName, cancellationToken);
https://github.com/danzuep/MailKitSimplified/blob/9b2ad4eff29e3e65c7612b1a01bd62cfc2bad774/source/MailKitSimplified.Receiver/Services/MailFolderClient.cs#L189
And as regards moving to a different folder in Google. no joy so far. My Processed label does not appear in the list obtained from await imapReceiver.GetMailFolderNamesAsync(ct);
but Spam does, so I have been trying to get hold of that using await imapReceiver.MailFolderClient.GetFolderAsync([folder], ct);
. this does not work (I just get null) for Processed, Spam and [Gmail]/Spam. (this link seemed to suggest that [Gmail]/Spam might be recognised).
No idea what to do next. Why does Gmail have to be different?
Maybe create the new folder manually in Gmail, then use await mailFolderClient.MoveToAsync(messageSummary, destinationMailFolderFullName);
It's for a charity right? I should have some time to look at it tomorrow 🙂
Yes I can try a couple of things tomorrow. Have to go out and play some music now. And yes I am doing the work for a charity - Campaign against Antisemitism. An online system for onboarding volunteers and then managing them. I am retired but still seem to keep pretty busy, and this is a lot more interesting than WordPress!
Seems there is no easy way to get all Gmail labels. The good news though is that you don't need to!
Download the latest pre-release version, then use this to create a "Processed" label in Gmail:
var mailFolder = await mailFolderClient.GetOrCreateFolderAsync(mailFolderFullName, cancellationToken);
Once you've made the label you just move it like this:
var uniqueId = await mailFolderClient.MoveToAsync(messageSummary, destinationFolderFullName, cancellationToken);
Wow that's great thanks a lot. I just have a meeting with the guy from CAA but I will try this out afterwards.
Yes I can confirm this is working. Thanks again.
I raised an issue previously about trying to move emails from INBOX to a Processed folder. The suggestions all worked fine when I was trying it out on my own mail server. However the charity i am doing the work for use google mail. From all I have read online google do not really have folders, they have labels. On the web I created a Processed label and moved some emails into it and that all seemed to work. Apparently google use imap calls for folders to control labels. But I can;t seem to make it work. First I am getting a list of all the folders, Processed does not appear.
I am trying to get hold of the folder using
and getting an exception as folder not found. The same happens if I try Spam. So really the question is how do I do this with Google?