Summary description for ImapClient
        public static void Run()
        {
            //ExStart:SSLEnabledIMAPServer
            // Create an instance of the ImapClient class
            ImapClient client = new ImapClient();
            // Specify host, username and password, Port and SecurityOptions for your client
            client.Host = "imap.gmail.com";
            client.Username = "[email protected]";
            client.Password = "your.password";
            client.Port = 993;
            client.SecurityOptions = SecurityOptions.Auto;

            try
            {
                Console.WriteLine("Logged in to the IMAP server");
                // Disconnect to the remote IMAP server
                client.Dispose();
                Console.WriteLine("Disconnected from the IMAP server");
            }
            catch (Exception ex)
            {
                Console.Write(Environment.NewLine + ex);
            }
            //ExEnd:SSLEnabledIMAPServer
            Console.WriteLine(Environment.NewLine + "Connected to IMAP server with SSL.");
        }
Example #2
0
        private List<string> CheckForMessages()
        {
            var messages = new List<string>();

            _client = new ImapClient(_IMAPClientUri, true);
            if (_client.Connect() && _client.Login(_IMAPUsername, _IMAPPassword))
            {
                try
                {
                    var keyword = _subjectKeyword;                    
                    var emails = _client.Folders.Inbox.Search(string.Format("UNSEEN SUBJECT \"{0}\"", keyword), ImapX.Enums.MessageFetchMode.Full);
                    Console.WriteLine(string.Format("{0} emails", emails.Count()));
                    foreach (var email in emails)
                    {
                        messages.Add(email.Body.Text);
                        email.Remove();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
                finally
                {
                    _client.Logout();
                    _client.Disconnect();                    
                }
            }
            else
            {
                Console.WriteLine("Bad email login");
            }
            return messages;
        }
        public static void Run()
        {
            //ExStart:SettingMessageFlags
            // Create an instance of the ImapClient class
            ImapClient client = new ImapClient();

            // Specify host, username, password, Port and SecurityOptions for your client
            client.Host = "imap.gmail.com";
            client.Username = "[email protected]";
            client.Password = "your.password";
            client.Port = 993;
            client.SecurityOptions = SecurityOptions.Auto;

            try
            {
                Console.WriteLine("Logged in to the IMAP server");
                // Mark the message as read and Disconnect to the remote IMAP server
                client.ChangeMessageFlags(1, ImapMessageFlags.IsRead);
                client.Dispose();
            }
            catch (Exception ex)
            {
                Console.Write(Environment.NewLine + ex);
            }
            //ExEnd:SettingMessageFlags
            Console.WriteLine(Environment.NewLine + "Set message flags from IMAP server.");
        }
    protected void brnSendEmail_Click(object sender, EventArgs e)
    {
        lblMessage.Text = "";

        try
        {
            // initialize imap client
            ImapClient client = new ImapClient();
            client.Host = txtHost.Text;
            client.Port = int.Parse(txtPort.Text);
            client.Username = txtUsername.Text;
            client.Password = txtPassword.Text;

            // connect to imap server and login
            client.Connect(true);
            lblMessage.ForeColor = Color.Green;
            lblMessage.Text = "Successfully connected to IMAP Mail server.<br><hr>";

            client.Disconnect();
        }
        catch (Exception ex)
        {
            lblMessage.ForeColor = Color.Red;
            lblMessage.Text = "Error: " + ex.Message;
        }
    }
        public static void Run()
        {
            //ExStart:DeletingFolders
            // Create an instance of the ImapClient class
            ImapClient client = new ImapClient();

            // Specify host, username and password, and set port for your client
            client.Host = "imap.gmail.com";
            client.Username = "[email protected]";
            client.Password = "your.password";
            client.Port = 993;
            client.SecurityOptions = SecurityOptions.Auto;
            try
            {
                // Rename a folder and Disconnect to the remote IMAP server
                client.DeleteFolder("Client");
                client.Dispose();
            }
            catch (Exception ex)
            {
                Console.Write(Environment.NewLine + ex);
            }
            //ExEnd:DeletingFolders
            Console.WriteLine(Environment.NewLine + "Deleted folders on IMAP server.");
        }
        public static void Run()
        {
            //ExStart:AddingNewMessage
            // Create a message
            MailMessage msg = new MailMessage("[email protected]", "[email protected]", "subject", "message");

            // Create an instance of the ImapClient class
            ImapClient client = new ImapClient();

            // Specify host, username, password, port and SecurityOptions for your client
            client.Host = "imap.gmail.com";
            client.Username = "[email protected]";
            client.Password = "your.password";
            client.Port = 993;
            client.SecurityOptions = SecurityOptions.Auto;
            try
            {
                // Subscribe to the Inbox folder, Append the newly created message and Disconnect to the remote IMAP server
                client.SelectFolder(ImapFolderInfo.InBox);
                client.SubscribeFolder(client.CurrentFolder.Name);
                client.AppendMessage(client.CurrentFolder.Name, msg);
                Console.WriteLine("New Message Added Successfully");
                client.Dispose();
            }
            catch (Exception ex)
            {
                Console.Write(Environment.NewLine + ex);
            }
            Console.WriteLine(Environment.NewLine + "Added new message on IMAP server.");
            //ExEnd:AddingNewMessage
        }
        public static void Run()
        {
            // ExStart:SupportIMAPIdleCommand
            // Connect and log in to IMAP 
            ImapClient client = new ImapClient("imap.domain.com", "username", "password");

            ManualResetEvent manualResetEvent = new ManualResetEvent(false);
            ImapMonitoringEventArgs eventArgs = null;
            client.StartMonitoring(delegate(object sender, ImapMonitoringEventArgs e)
            {
                eventArgs = e;
                manualResetEvent.Set();
            });
            Thread.Sleep(2000);
            SmtpClient smtpClient = new SmtpClient("exchange.aspose.com", "username", "password");
            smtpClient.Send(new MailMessage("[email protected]", "[email protected]", "EMAILNET-34875 - " + Guid.NewGuid(), "EMAILNET-34875 Support for IMAP idle command"));
            manualResetEvent.WaitOne(10000);
            manualResetEvent.Reset();
            Console.WriteLine(eventArgs.NewMessages.Length);
            Console.WriteLine(eventArgs.DeletedMessages.Length);
            client.StopMonitoring("Inbox");
            smtpClient.Send(new MailMessage("[email protected]", "[email protected]", "EMAILNET-34875 - " + Guid.NewGuid(), "EMAILNET-34875 Support for IMAP idle command"));
            manualResetEvent.WaitOne(5000);
            // ExEnd:SupportIMAPIdleCommand
        }
        public static void Run()
        {
            //ExStart:DeleteSingleMessage
            using (ImapClient client = new ImapClient("exchange.aspose.com", "username", "password"))
            {
                try
                {
                    Console.WriteLine(client.UidPlusSupported.ToString());
                    // Append some test messages
                    client.SelectFolder(ImapFolderInfo.InBox);
                    MailMessage message = new MailMessage("[email protected]", "[email protected]", "EMAILNET-35227 - " + Guid.NewGuid(), "EMAILNET-35227 Add ability in ImapClient to delete message");
                    string emailId = client.AppendMessage(message);

                    // Now verify that all the messages have been appended to the mailbox
                    ImapMessageInfoCollection messageInfoCol = null;
                    messageInfoCol = client.ListMessages();
                    Console.WriteLine(messageInfoCol.Count);

                    // Select the inbox folder and Delete message
                    client.SelectFolder(ImapFolderInfo.InBox);
                    client.DeleteMessage(emailId);
                    client.CommitDeletes();
                }
                finally
                {

                }
            }
            //ExEnd:DeleteSingleMessage
        }
        public static void Run()
        {
            // ExStart:InternalDateFilter
            // Connect and log in to IMAP
            const string host = "host";
            const int port = 143;
            const string username = "[email protected]";
            const string password = "password";
            ImapClient client = new ImapClient(host, port, username, password);
            client.SelectFolder("Inbox");

            // Set conditions, Subject contains "Newsletter", Emails that arrived today
            ImapQueryBuilder builder = new ImapQueryBuilder();
            builder.Subject.Contains("Newsletter");
            builder.InternalDate.On(DateTime.Now);
            // Build the query and Get list of messages
            MailQuery query = builder.GetQuery();
            ImapMessageInfoCollection messages = client.ListMessages(query);
            foreach (ImapMessageInfo info in messages)
            {
                Console.WriteLine("Internal Date: " + info.InternalDate);
            }
            // Disconnect from IMAP
            client.Dispose();
            // ExEnd:InternalDateFilter
        }
        // ExStart:ReadMessagesRecursively
        public static void Run()
        {
            // Create an instance of the ImapClient class
            ImapClient client = new ImapClient();

            // Specify host, username, password, Port and SecurityOptions for your client
            client.Host = "imap.gmail.com";
            client.Username = "[email protected]";
            client.Password = "your.password";
            client.Port = 993;
            client.SecurityOptions = SecurityOptions.Auto;
            try
            {
                // The root folder (which will be created on disk) consists of host and username
                string rootFolder = client.Host + "-" + client.Username;

                // Create the root folder and List all the folders from IMAP server
                Directory.CreateDirectory(rootFolder);
                ImapFolderInfoCollection folderInfoCollection = client.ListFolders();
                foreach (ImapFolderInfo folderInfo in folderInfoCollection)
                {
                    // Call the recursive method to read messages and get sub-folders
                    ListMessagesInFolder(folderInfo, rootFolder, client);
                }
                // Disconnect to the remote IMAP server
                client.Dispose();
            }
            catch (Exception ex)
            {
                Console.Write(Environment.NewLine + ex);
            }

            Console.WriteLine(Environment.NewLine + "Downloaded messages recursively from IMAP server.");
        }
Example #11
0
        private IEnumerable<Chat> ProcessChats(ImapClient client)
        {
            var folder = client.GetChatsFolder();

            return Enumerable.Range(_startIndex, _stopIndex - _startIndex)
                .Where(i => i < folder.Messages.Count)
                .Select(i => ChatFromImapMessage(folder.Messages[i]));
        }
 public GMailMessageLabelCollection(ImapClient client, Message message)
     : base(client, message)
 {
     AddType = "+X-GM-LABELS";
     RemoveType = "-X-GM-LABELS";
     IsUTF7 = true;
     AddQuotes = true;
 }
 internal bool GmailAuthenticate(string username, string password)
 {
     var client = new ImapClient("imap.gmail.com", 993, true, true);
     client.Connect();
     bool result = client.Login(username,password);
     if (result) return true;
     else return false;
 }
    protected void gvMessages_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "DisplayMessage")
        {
            pnlMessage.Visible = true;
            string msgSequenceNumber = e.CommandArgument.ToString();

            try
            {
                // initialize imap client
                ImapClient client = new ImapClient();
                client.Host = txtHost.Text;
                client.Port = int.Parse(txtPort.Text);
                client.Username = txtUsername.Text;
                client.Password = Session["Password"].ToString();

                // SSL Settings
                if (chSSL.Checked == true)
                {
                    client.EnableSsl = true;
                    client.SecurityMode = ImapSslSecurityMode.Implicit;
                }

                // connect to pop3 server and login
                client.Connect(true);
                client.SelectFolder(ImapFolderInfo.InBox);
                lblMessage.ForeColor = Color.Green;
                lblMessage.Text = "Successfully connected to Imap Mail server.<br><hr>";

                // get the message
                MailMessage msg = client.FetchMessage(int.Parse(msgSequenceNumber));
                // sender name and address
                litFrom.Text = msg.From[0].DisplayName + " <" + msg.From[0].Address + ">";
                // to addresses
                litTo.Text = "";
                foreach (MailAddress address in msg.To)
                {
                    litTo.Text += address.DisplayName + " <" + address.Address + "> , ";
                }
                // cc addresses
                litCc.Text = "";
                foreach (MailAddress address in msg.CC)
                {
                    litCc.Text += address.DisplayName + " <" + address.Address + "> , ";
                }
                // subject
                litSubject.Text = msg.Subject;
                litBody.Text = msg.HtmlBody;

                client.Disconnect();
            }
            catch (Exception ex)
            {
                lblMessage.ForeColor = Color.Red;
                lblMessage.Text = "Error: " + ex.Message;
            }
        }
    }
 public void getFolders(string canvasid, int windowid)
 {
     ImapClient imp = new ImapClient(ccl.InputParams[2].ToString(), 993, ccl.InputParams[0].ToString(), ccl.InputParams[1].ToString(), true);
     List<string> mailboxes = imp.GetAllFolders();
     foreach(string mb in mailboxes){
         parameters.Add(mb);
     }
     imp.Logout();
 }
 /// <summary>
 /// Connects to the imap server.
 /// </summary>
 /// <param name="login">Login credidentials containing username and password of user</param>
 /// <param name="server">Server address to connect to</param>
 public void Connect(LoginCred login, string server)
 {
     imapc = new ImapClient(server, true);
       if (imapc.Connect())
     if (imapc.Login(login.Username, login.Password))
     {
       blnConnected = true;
       imapc.Behavior.AutoPopulateFolderMessages = true;
     }
 }
 public void getMailMessage(string canvasid, int windowid)
 {
     ImapClient imp = new ImapClient(ccl.InputParams[2].ToString(), 993, ccl.InputParams[0].ToString(), ccl.InputParams[1].ToString(), true);
     List<object> arlmsg = new List<object>();
     arlmsg.Add("");
     arlmsg.Add("");
     arlmsg.Add("");
     arlmsg.Add(XmlEscape(imp.GetMessageBody(ccl.InputParams[3].ToString(), ccl.InputParams[4].ToString())));
     parameters.Add(arlmsg);
 }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_IMAP();
            string dstEmail = dataDir + "1234.eml";

            // Create a message
            Aspose.Email.Mail.MailMessage msg;
            msg = new Aspose.Email.Mail.MailMessage(
            "[email protected]",
            "[email protected]",
            "subject",
            "message"
            );

            //Create an instance of the ImapClient class
            ImapClient client = new ImapClient();

            //Specify host, username and password for your client
            client.Host = "imap.gmail.com";

            // Set username
            client.Username = "[email protected]";

            // Set password
            client.Password = "your.password";

            // Set the port to 993. This is the SSL port of IMAP server
            client.Port = 993;

            // Enable SSL
            client.SecurityOptions = SecurityOptions.Auto;

            try
            {
                // Subscribe to the Inbox folder
                client.SelectFolder(ImapFolderInfo.InBox);
                client.SubscribeFolder(client.CurrentFolder.Name);

                // Append the newly created message
                client.AppendMessage(client.CurrentFolder.Name, msg);

                System.Console.WriteLine("New Message Added Successfully");

                //Disconnect to the remote IMAP server
                client.Disconnect();

            }
            catch (Exception ex)
            {
                System.Console.Write(Environment.NewLine + ex.ToString());
            }

            Console.WriteLine(Environment.NewLine + "Added new message on IMAP server.");
        }
        public static void Run()
        {
            try
            {

            // ExStart:SendIMAPasynchronousEmail
            // Create an imapclient with host, user and password
            ImapClient client = new ImapClient();
            client.Host = "domain.com";
            client.Username = "username";
            client.Password = "password";
            client.SelectFolder("InBox");

            ImapMessageInfoCollection messages = client.ListMessages();
            IAsyncResult res1 = client.BeginFetchMessage(messages[0].UniqueId);
            IAsyncResult res2 = client.BeginFetchMessage(messages[1].UniqueId);
            MailMessage msg1 = client.EndFetchMessage(res1);
            MailMessage msg2 = client.EndFetchMessage(res2);

            // ExEnd:SendIMAPasynchronousEmail

            // ExStart:SendIMAPasynchronousEmailThreadPool
            List<MailMessage> List = new List<MailMessage>();
            ThreadPool.QueueUserWorkItem(delegate(object o)
            {
                client.SelectFolder("folderName");
                ImapMessageInfoCollection messageInfoCol = client.ListMessages();
                foreach (ImapMessageInfo messageInfo in messageInfoCol)
                {
                    List.Add(client.FetchMessage(messageInfo.UniqueId));
                }
            });
            // ExEnd:SendIMAPasynchronousEmailThreadPool

            // ExStart:SendIMAPasynchronousEmailThreadPool1
            List<MailMessage> List1 = new List<MailMessage>();
            ThreadPool.QueueUserWorkItem(delegate(object o)
            {
                using (IDisposable connection = client.CreateConnection())
                {
                    client.SelectFolder("FolderName");
                    ImapMessageInfoCollection messageInfoCol =
               client.ListMessages();
                    foreach (ImapMessageInfo messageInfo in messageInfoCol)
                        List1.Add(client.FetchMessage(messageInfo.UniqueId));
                }
            });
            // ExEnd:SendIMAPasynchronousEmailThreadPool1
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
                throw;
            }
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_IMAP();
            string dstEmail = dataDir + "1234.eml";

            //Create an instance of the ImapClient class
            ImapClient client = new ImapClient();

            //Specify host, username and password for your client
            client.Host = "imap.gmail.com";

            // Set username
            client.Username = "[email protected]";

            // Set password
            client.Password = "your.password";

            // Set the port to 993. This is the SSL port of IMAP server
            client.Port = 993;

            // Enable SSL
            client.SecurityOptions = SecurityOptions.Auto;

            try
            {
                // Get all folders in the currently subscribed folder
                Aspose.Email.Imap.ImapFolderInfoCollection folderInfoColl = client.ListFolders();

                // Iterate through the collection to get folder info one by one
                foreach (Aspose.Email.Imap.ImapFolderInfo folderInfo in folderInfoColl)
                {
                    // Folder name
                    Console.WriteLine("Folder name is " + folderInfo.Name);
                    ImapFolderInfo folderExtInfo = client.ListFolder(folderInfo.Name);
                    // New messages in the folder
                    Console.WriteLine("New message count: " + folderExtInfo.NewMessageCount);
                    // Check whether its readonly
                    Console.WriteLine("Is it readonly? " + folderExtInfo.ReadOnly);
                    // Total number of messages
                    Console.WriteLine("Total number of messages " + folderExtInfo.TotalMessageCount);
                }

                //Disconnect to the remote IMAP server
                client.Disconnect();

            }
            catch (Exception ex)
            {
                System.Console.Write(Environment.NewLine + ex.ToString());
            }

            Console.WriteLine(Environment.NewLine + "Getting folders information from IMAP server.");
        }
        static void Run()
        { 
            // ExStart: MoveMessage
            ///<summary>
            /// This example shows how to move a message from one folder of a mailbox to another one using the ImapClient API of Aspose.Email for .NET
            /// Available from Aspose.Email for .NET 6.4.0 onwards
            /// -------------- Available API Overload Members --------------
            /// Void ImapClient.MoveMessage(IConnection iConnection, int sequenceNumber, string folderName, bool commitDeletions)
            /// Void ImapClient.MoveMessage(IConnection iConnection, string uniqueId, string folderName, bool commitDeletions)
            /// Void ImapClient.MoveMessage(int sequenceNumber, string folderName, bool commitDeletions)
            /// Void ImapClient.MoveMessage(string uniqueId, string folderName, bool commitDeletions)
            /// Void ImapClient.MoveMessage(IConnection iConnection, int sequenceNumber, string folderName)
            /// Void ImapClient.MoveMessage(IConnection iConnection, string uniqueId, string folderName)
            /// Void ImapClient.MoveMessage(int sequenceNumber, string folderName)
            /// Void ImapClient.MoveMessage(string uniqueId, string folderName)
            ///</summary>

            using (ImapClient client = new ImapClient("host.domain.com", 993, "username", "password"))
            {
                string folderName = "EMAILNET-35151";
                if (!client.ExistFolder(folderName))
                    client.CreateFolder(folderName);
                try
                {
                    MailMessage message = new MailMessage(
                        "[email protected]",
                        "[email protected]",
                        "EMAILNET-35151 - " + Guid.NewGuid(),
                        "EMAILNET-35151 ImapClient: Provide option to Move Message");
                    client.SelectFolder(ImapFolderInfo.InBox);
                    // Append the new message to Inbox folder
                    string uniqueId = client.AppendMessage(ImapFolderInfo.InBox, message);
                    ImapMessageInfoCollection messageInfoCol1 = client.ListMessages();
                    Console.WriteLine(messageInfoCol1.Count);
                    // Now move the message to the folder EMAILNET-35151
                    client.MoveMessage(uniqueId, folderName);
                    client.CommitDeletes();
                    // Verify that the message was moved to the new folder
                    client.SelectFolder(folderName);
                    messageInfoCol1 = client.ListMessages();
                    Console.WriteLine(messageInfoCol1.Count);
                    // Verify that the message was moved from the Inbox
                    client.SelectFolder(ImapFolderInfo.InBox);
                    messageInfoCol1 = client.ListMessages();
                    Console.WriteLine(messageInfoCol1.Count);
                }
                finally
                {
                    try { client.DeleteFolder(folderName); }
                    catch { }
                }
            }
            // ExEnd: MoveMessage
        }
Example #22
0
        public static ImapClient FromLoginInfo(string username, string password)
        {
            var imapClient = new ImapClient("imap.gmail.com", 993, true);

            if (!imapClient.Connection())
                throw new Exception("Could not connect!");
            if (!imapClient.LogIn(username, password))
                throw new Exception("Could not log in!");

            return imapClient;
        }
Example #23
0
        //http://imapx.codeplex.com/documentation
        static void Main(string[] args)
        {
            // ApplicationTrustPolicy.TrustAll();

            string credientials = ConfigurationManager.AppSettings["credentials"];
            string imap_server = ConfigurationManager.AppSettings["imap_server"];
            string logfilename = ConfigurationManager.AppSettings["log"];
            string output_dir = ConfigurationManager.AppSettings["output_dir"];
            string email_folder = ConfigurationManager.AppSettings["email_folder"];

            var client = new ImapClient(imap_server, true,false);

            if (logfilename != null)
            {
                Logger.EnableLogger();
                Logger.WriteLine("logging to '" + logfilename + "'");
                Debug.Listeners.Add(new TextWriterTraceListener(logfilename));
                Debug.AutoFlush = true;
                client.IsDebug = true;
            }

            var files = Directory.GetFiles(credientials, "*.*");
            var user =  Path.GetFileName(files[0]);
            var pass = File.ReadAllLines(files[0])[0];
            Logger.WriteLine("about to connect:");
            if (client.Connect())
            {

                if (client.Login(user,pass))
                {
                    // login successful
                    Console.WriteLine("ok");
                    Logger.WriteLine("listing labels...");
                    foreach (var item in client.Folders)
                    {
                        Logger.WriteLine(item.Name);
                    }

                    var folder = client.Folders[email_folder];
                   folder.Messages.Download("UNSEEN", MessageFetchMode.Basic | MessageFetchMode.GMailExtendedData, 72);
                   var s = GetSerieData(folder);
                    var cbtt = "mpci";
                    var pcode="qp2";

                    string fn = "instant_" + cbtt + "_" + pcode + "_" + DateTime.Now.ToString("MMMdyyyyHHmmssfff") + ".txt";
                    fn = Path.Combine(output_dir, fn);
                   HydrometInstantSeries.WriteToHydrometFile(s, cbtt, pcode, "hydromet", fn);
                }
            }
            else
            {
                Logger.WriteLine("connection not successful");
            }
        }
        static void Run()
        {
            // ExStart: ListingMessagesWithPagingSupport
            ///<summary>
            /// This example shows the paging support of ImapClient for listing messages from the server
            /// Available in Aspose.Email for .NET 6.4.0 and onwards
            ///</summary>
            using (ImapClient client = new ImapClient("host.domain.com", 993, "username", "password"))
            {
                try
                {
                    int messagesNum = 12;
                    int itemsPerPage = 5;
                    MailMessage message = null;
                    // Create some test messages and append these to server's inbox
                    for (int i = 0; i < messagesNum; i++)
                    {
                        message = new MailMessage(
                            "[email protected]",
                            "[email protected]",
                            "EMAILNET-35157 - " + Guid.NewGuid(),
                            "EMAILNET-35157 Move paging parameters to separate class");
                        client.AppendMessage(ImapFolderInfo.InBox, message);
                    }

                    // List messages from inbox
                    client.SelectFolder(ImapFolderInfo.InBox);
                    ImapMessageInfoCollection totalMessageInfoCol = client.ListMessages();
                    // Verify the number of messages added
                    Console.WriteLine(totalMessageInfoCol.Count);

                    ////////////////// RETREIVE THE MESSAGES USING PAGING SUPPORT////////////////////////////////////

                    List<ImapPageInfo> pages = new List<ImapPageInfo>();
                    ImapPageInfo pageInfo = client.ListMessagesByPage(itemsPerPage);
                    Console.WriteLine(pageInfo.TotalCount);
                    pages.Add(pageInfo);
                    while (!pageInfo.LastPage)
                    {
                        pageInfo = client.ListMessagesByPage(pageInfo.NextPage);
                        pages.Add(pageInfo);
                    }
                    int retrievedItems = 0;
                    foreach (ImapPageInfo folderCol in pages)
                        retrievedItems += folderCol.Items.Count;
                    Console.WriteLine(retrievedItems);
                }
                finally
                {
                }
            }
            // ExEnd: ListingMessagesWithPagingSupport
        }
 public static void Run()
 {
     // ExStart:RetreivingServerExtensions
     // Connect and log in to IMAP
     ImapClient client = new ImapClient("imap.gmail.com", "username", "password");
     string[] getCapabilities = client.GetCapabilities();
     foreach (string getCap in getCapabilities)
     {
         Console.WriteLine(getCap);
     }
     // ExEnd:RetreivingServerExtensions
 }
    private void DownloadFile(string msgSequenceNumber, string format)
    {
        try
        {
            // initialize imap client
            ImapClient client = new ImapClient();
            client.Host = txtHost.Text;
            client.Port = int.Parse(txtPort.Text);
            client.Username = txtUsername.Text;
            client.Password = Session["Password"].ToString();

            // SSL Settings
            if (chSSL.Checked == true)
            {
                client.EnableSsl = true;
                client.SecurityMode = ImapSslSecurityMode.Implicit;
            }

            // connect to imap server and login
            client.Connect(true);
            client.SelectFolder(ImapFolderInfo.InBox);
            lblMessage.ForeColor = Color.Green;
            lblMessage.Text = "Successfully connected to Imap Mail server.<br><hr>";

            // get the message
            MemoryStream stream = new MemoryStream();
            MailMessage msg = client.FetchMessage(int.Parse(msgSequenceNumber));
            if (format == "eml")
                msg.Save(stream, MessageFormat.Eml);
            else
                msg.Save(stream, MessageFormat.Msg);
            stream.Position = 0;
            byte[] msgBytes = new byte[stream.Length];
            stream.Read(msgBytes, 0, (int)stream.Length);

            client.Disconnect();

            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("Content-Length", msgBytes.Length.ToString());
            Response.AddHeader("Content-Disposition", "attachment; filename=Message." + format);
            Response.ContentType = "application/octet-stream";
            Response.BinaryWrite(msgBytes);
            Response.End();

        }
        catch (Exception ex)
        {
            lblMessage.ForeColor = Color.Red;
            lblMessage.Text = "Error: " + ex.Message;
        }
    }
Example #27
0
    public static void Main(string[] args)
    {
        ImapConnection.ServerCertificateValidationCallback += delegate {
          // 適切な証明書の検証を行うように書き換えてください
          return true;
        };

        using (var client = new ImapClient(new Uri("imap://[email protected]/"))) {
          client.Connect("pass");

          Console.WriteLine("connected!!");
        }
    }
 public static void Run()
 {
     // ExStart:GetMessageIdUsingImapMessageInfo
     // Create an imapclient with host, user and password
     ImapClient client = new ImapClient();
     client.Host = "domain.com";
     client.Username = "username";
     client.Password = "password";
     client.SelectFolder("InBox");
     ImapMessageInfoCollection msgsColl = client.ListMessages(true);
     Console.WriteLine("Total Messages: " + msgsColl.Count);
     // ExEnd:GetMessageIdUsingImapMessageInfo
 }
Example #29
0
        private static bool Connect(ImapClient client)
        {
            if (client.Connect())
            {
                //if (client.Login(MailLogin, MailPassword))
                if (client.Login("[email protected]", "1597534682"))
                {
                    return true;
                }
            }

            return false;
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_IMAP();
            string dstEmail = dataDir + "1234.eml";

            //Create an instance of the ImapClient class
            ImapClient client = new ImapClient();

            //Specify host, username and password for your client
            client.Host = "imap.gmail.com";

            // Set username
            client.Username = "[email protected]";

            // Set password
            client.Password = "your.password";

            // Set the port to 993. This is the SSL port of IMAP server
            client.Port = 993;

            // Enable SSL
            client.SecurityOptions = SecurityOptions.Auto;

            try
            {
                // The root folder (which will be created on disk) consists of host and username
                string rootFolder = client.Host + "-" + client.Username;
                // Create the root folder
                Directory.CreateDirectory(rootFolder);

                // List all the folders from IMAP server
                ImapFolderInfoCollection folderInfoCollection = client.ListFolders();
                foreach (ImapFolderInfo folderInfo in folderInfoCollection)
                {
                    // Call the recursive method to read messages and get sub-folders
                    ListMessagesInFolder(folderInfo, rootFolder, client);
                }


                //Disconnect to the remote IMAP server
                client.Disconnect();

            }
            catch (Exception ex)
            {
                System.Console.Write(Environment.NewLine + ex.ToString());
            }

            Console.WriteLine(Environment.NewLine + "Downloaded messages recursively from IMAP server.");
        }