Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MailKit Set MessageFlag Seen after Append

I send a MailKit.Message Async with the MailKit.Net.Smtp.SmtpClient.

Then i put the Mail in the send Folder, but the Message Flag is Unseen.

I can't set the messageflag in Message build, only after Append, but i found no way to convert the MailKit.UniqueId? to MailKit.UniqueId.

 var folderSend = IC.GetFolder(MailKit.SpecialFolder.Sent);
 MailKit.UniqueId? te = folderSend.Append(nochmalMessage);
 folderSend.AddFlagsAsync(te, MailKit.MessageFlags.Seen, true);

te must be MailKit.UniqueId

like image 992
Wolfgang Schorge Avatar asked Feb 06 '26 23:02

Wolfgang Schorge


1 Answers

The Append() and AppendAsync() methods each have an overload that takes a MessageFlags argument. This allows you to simplify your logic down to:

folder.Append (message, MessageFlags.Seen);

or

await folder.AppendAsync (message, MessageFlags.Seen);

This eliminates the need to even bother calling AddFlags() or AddFlagsAsync() with the flags you want to set on the appended message because it'll set those flags as it appends the message.

like image 188
jstedfast Avatar answered Feb 09 '26 12:02

jstedfast