Changes the flags of an email on IMAP4 server.
[Visual Basic] Public Sub ChangeMailFlags( _ info As MailInfo, _ flags As String _ ) Public Async Function ChangeMailFlagsAsync( _ info As MailInfo, _ flags As String _ ) As Task
[C#] public void ChangeMailFlags( MailInfo info, string flags ); public async Task ChangeMailFlagsAsync( MailInfo info, string flags );
[C++] public: void ChangeMailFlags( MailInfo^ info, String^ flags );
[JScript] public function ChangeMailFlags( info: MailInfo, flags: String );
Parameters
Example
[Visual Basic, C#, C++] The following example demonstrates how to mark \Seen and \Deleted flags to every email in "INBOX" with EAGetMail POP3 & IMAP Component. To get the full samples of EAGetMail, please refer to Samples section.
[VB - Change email IMAP4 flags] Imports System Imports System.Globalization Imports System.IO Imports System.Text Imports EAGetMail Public Class TestClass Public Sub ChangeMailFlags(server As String, user As String, password As String, useSsl As Boolean) Try ' Most modern email server require SSL/TLS connection, ' set useSsl to true Is recommended. Dim oServer As New MailServer(server, user, password, useSsl, ServerAuthType.AuthLogin, ServerProtocol.Imap4) ' IMAP4 port Is 143, IMAP4 SSL port Is 993. oServer.Port = If(useSsl, 993, 143) Console.WriteLine("Connecting server ...") Dim oClient As New MailClient("TryIt") oClient.Connect(oServer) Console.WriteLine("Retrieving email list ...") Dim infos() As MailInfo = oClient.GetMailInfos() Console.WriteLine("Total {0} email(s)", infos.Length) For i As Integer = 0 To infos.Length - 1 Dim info As MailInfo = infos(i) oClient.ChangeMailFlags(info, "(\Seen \Deleted)") Console.WriteLine("Flags: {0}", info.IMAP4MailFlags) Next Console.WriteLine("Disconnecting ...") oClient.Logout() Console.WriteLine("Completed!") Catch ep As Exception Console.WriteLine("Error: {0}", ep.Message) End Try End Sub End Class
[C# - Change email IMAP4 flags] using System; using System.IO; using System.Globalization; using System.Text; using EAGetMail; class TestClass { public void ChangeMailFlags(string server, string user, string password, bool useSsl) { try { // Most modern email server require SSL/TLS connection, // set useSsl to true is recommended. MailServer oServer = new MailServer(server, user, password, useSsl, ServerAuthType.AuthLogin, ServerProtocol.Imap4); // IMAP4 port is 143, IMAP4 SSL port is 993. oServer.Port = (useSsl) ? 993 : 143; Console.WriteLine("Connecting server ..."); MailClient oClient = new MailClient("TryIt"); oClient.Connect(oServer); Console.WriteLine("Retreiving email list ..."); MailInfo[] infos = oClient.GetMailInfos(); Console.WriteLine("Total {0} email(s)", infos.Length); for (int i = 0; i < infos.Length; i++) { MailInfo info = infos[i]; oClient.ChangeMailFlags(info, "(\\Seen \\Deleted)"); Console.WriteLine("Flags: {0}", info.IMAP4MailFlags); } Console.WriteLine("Disconnecting ..."); oClient.Logout(); Console.WriteLine("Completed!"); } catch (Exception ep) { Console.WriteLine("Error: {0}", ep.Message); } } }
[C++/CLI - Change email IMAP4 flags] using namespace System; using namespace System::Globalization; using namespace System::IO; using namespace EAGetMail; //add EAGetMail namespace void ChangeMailFlags(String ^server, String ^user, String ^password, bool useSsl) { try { // Most modern email server require SSL/TLS connection, // set useSsl to true is recommended. MailServer ^oServer = gcnew MailServer(server, user, password, useSsl, ServerAuthType::AuthLogin, ServerProtocol::Imap4); // IMAP4 port is 143, IMAP4 SSL port is 993. oServer->Port = (useSsl) ? 993 : 143; Console::WriteLine("Connecting server ..."); MailClient ^oClient = gcnew MailClient("TryIt"); oClient->Connect(oServer); Console::WriteLine("Retreiving email list ..."); array<MailInfo^>^infos = oClient->GetMailInfos(); Console::WriteLine("Total {0} email(s)", infos->Length); for (int i = 0; i < infos->Length; i++) { MailInfo ^info = infos[i]; oClient->ChangeMailFlags(info, "(\\Seen \\Deleted)"); Console::WriteLine("Flags: {0}", info->IMAP4MailFlags); } Console::WriteLine("Disconnecting ..."); oClient->Logout(); Console::WriteLine("Completed!"); } catch (Exception ^ep) { Console::WriteLine("Error: {0}", ep->Message); } }
See Also