public void move()
        {
            // move specific emails
            using (ImapClient Client = new ImapClient("imap.gmail.com", 993, "*****@*****.**", "aq1sw2de3fr4", AuthMethod.Login, true))
            {
                IEnumerable <uint> uids = Client.Search(SearchCondition.All());

                foreach (uint uid in uids)
                {
                    MailMessage msg  = Client.GetMessage(uid, FetchOptions.Normal);
                    bool        move = false;

                    // process the message here
                    if (msg.Subject.Equals("Hello"))
                    {
                        Console.WriteLine("Hello message moving to trash...");
                        move = true;
                    }

                    if (move)
                    {
                        Client.MoveMessage(uid, "[Gmail]/Trash");
                    }
                }
            }
        }
        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(
                        "*****@*****.**",
                        "*****@*****.**",
                        "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
        }
        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(
                        "*****@*****.**",
                        "*****@*****.**",
                        "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
        }
示例#4
0
 public void DeleteMessage(EmailMessage email)
 {
     using (ImapClient client = new ImapClient(imapHost, 993, username, password, AuthMethod.Login, true))
     {
         try { client.MoveMessage(email.getUID(), "[Gmail]/Trash"); }
         catch (BadServerResponseException e)
         {
             //be really sad
         }catch (Exception e)
         {
             ALSMessageBox mb = new ALSMessageBox("Unknown error occurred");
             mb.Show();
         }
     }
 }
        public void getUnreadEmails()
        {
            InsuredTravelingEntity entities = new InsuredTravelingEntity();
            string n = "[notification]";

            using (ImapClient client = new ImapClient("imap.zoho.com", 993,
                                                      "*****@*****.**", "Enter4Sy", AuthMethod.Login, true))
            {
                IEnumerable <uint> uids = client.Search(SearchCondition.Unseen());

                foreach (uint uid in uids)
                {
                    MailMessage message = client.GetMessage(uid);
                    news_all    news    = entities.news_all.Create();;
                    news.Title            = message.Subject.Trim();
                    news.Content          = message.Body.Trim();
                    news.DataCreated      = (DateTime)message.Date();
                    news.InsuranceCompany = "Eurolink";
                    Random r = new Random();
                    //news.ID = r.Next(10000, 99999);
                    if (message.Subject.ToLower().StartsWith(n))
                    {
                        news.isNotification = true;
                    }
                    else
                    {
                        news.isNotification = false;
                    }

                    entities.news_all.Add(news);

                    client.MoveMessage(uid, "SeenNews");
                    client.DeleteMessage(uid, "Inbox");
                }

                client.Expunge("Inbox");
                client.Dispose();

                if (uids.Count() != 0)
                {
                    entities.SaveChanges();
                }
            }
        }
示例#6
0
        public ActionResult MoveEmail(uint EmailUDI, string ToMailBox, string Mailbox)
        {
            if (CheckLogin)
            {
                using (ImapClient Client = QLogin())
                {
                    try
                    {
                        Client.MoveMessage(EmailUDI, ToMailBox, Mailbox);

                        return(OkSuccess());
                    }
                    catch (Exception e)
                    {
                        return(BadRequestFail(e.Message));
                    }
                }
            }
            return(AccessDenied());
        }
示例#7
0
        //ReadEmail is the handler for email based detectors. It is designed
        //to retrieve email from a configured email service and parse the alerts
        public static void ReadEmail(string sVendor, string sFolderName, string sFolderNameTest, string sDetectorEmail, bool isParamTest)
        {
            switch (sVendor)
            {
            //Outlook based email plugin which requires the Outlook client to be installed.
            case "outlook":
                #region Microsoft Outlook Plugin
                //try
                //{
                //  //Setup connection information to mailstore
                //  //If logon information is null then mailstore must be open already
                //  //var oApp = new Microsoft.Office.Interop.Outlook.Application();
                //  //var sFolder = new Microsoft.Office.Interop.Outlook.Folder(sFolderName);
                //  //var oNameSpace = oApp.GetNamespace("MAPI");
                //  //oNameSpace.Logon(null, null, true, true);
                //  //var oInboxFolder = oNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
                //  //Outlook.Folder oFolder = oInboxFolder.Folder[sFolderName];

                //  //logging
                //  //Logging_Fido.Main.RunLogging("Running FIDO on file " + sFolderName);

                //  ////attach to folder and for each item in the folder then loop. During loop assign subject, body and detect malware type
                //  //foreach (var item in sFolder.Items)
                //  //{
                //  //  var oMailItem = item as Microsoft.Office.Interop.Outlook._MailItem;
                //  //  if (oMailItem != null)
                //  //  {
                //  //    var sMessageBody = oMailItem.Body;
                //  //  }
                //  //  if (oMailItem != null)
                //  //  {
                //  //    var sSubject = oMailItem.Subject;
                //  //  }
                //    //List<string> sERet = scan_email(sSubject, sMessageBody, sFolderName);
                //  //  if (sERet.First() == "Test Email")
                //  //  {
                //  //    oMailItem.Delete();
                //  //  }
                //  //  else
                //  //  {
                //  //    fido.Form1.Run_FIDO(sMessageBody, sERet, "fubar", false, false, true, sVendor);//MalwareType
                //  //    oMailItem.Delete();
                //  //  }
                //  }
                #endregion

                //}
                //catch (Exception e)
                //{
                //  Fido_Modules.Fido.Fido_EventHandler.SendEmail("Fido Error", "Fido Failed: {0} Exception caught in Outlook emailreceive area:" + e);
                //}
                break;

            case "exchange":
                #region Microsoft Exchange Plugin
                //still need to build out direct Exchange access
                #endregion
                break;

            //IMAP based email plugin which has been verified to work with Gmail
            case "imap":
                #region IMAP Plugin
                try
                {
                    //get encrypted password and decrypt
                    //then login
                    var sfidoemail  = Object_Fido_Configs.GetAsString("fido.email.fidoemail", null);
                    var sfidopwd    = Object_Fido_Configs.GetAsString("fido.email.fidopwd", null);
                    var sfidoacek   = Object_Fido_Configs.GetAsString("fido.email.fidoacek", null);
                    var sImapServer = Object_Fido_Configs.GetAsString("fido.email.imapserver", null);
                    var iImapPort   = Object_Fido_Configs.GetAsInt("fido.email.imapport", 0);
                    sfidoacek = Aes_Crypto.DecryptStringAES(sfidoacek, "1");
                    sfidopwd  = Aes_Crypto.DecryptStringAES(sfidopwd, sfidoacek);
                    IImapClient gLogin = new ImapClient(sImapServer, iImapPort, sfidoemail, sfidopwd, AuthMethod.Login, true);

                    var sSeperator = new[] { "," };
                    gLogin.DefaultMailbox = isParamTest ? sFolderNameTest : sFolderName;
                    var listUids = new List <uint>();

                    //seperate out list of email addresses handed to emailreceive
                    //then run query based on each email from the specified folder
                    //and finally convert to array
                    string[] aryInboxSearch = sDetectorEmail.Split(sSeperator, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var search in aryInboxSearch)
                    {
                        listUids.AddRange(gLogin.Search(SearchCondition.From(search)).ToList());
                    }
                    var uids = listUids.ToArray();
                    uids = uids.Take(50).ToArray();
                    var msg          = gLogin.GetMessages(uids);
                    var mailMessages = msg as MailMessage[] ?? msg.ToArray();
                    for (var i = 0; i < mailMessages.Count(); i++)
                    {
                        var sMessageBody = mailMessages[i].Body;
                        var sSubject     = mailMessages[i].Subject;
                        var sERet        = ScanEmail(sSubject, sMessageBody, sFolderName, isParamTest);
                        if (sERet == "Test Email")
                        {
                            Console.WriteLine(@"Test email found, putting in processed folder.");
                            gLogin.MoveMessage(uids[i], "Processed");
                        }
                        else
                        {
                            Console.WriteLine(@"Finished processing email alert, puttig in processed folder.");
                            gLogin.MoveMessage(uids[i], "Processed");
                        }
                    }
                    #endregion
                }
                catch (Exception e)
                {
                    Fido_EventHandler.SendEmail("Fido Error", "Fido Failed: {0} Exception caught in IMAP emailreceive area:" + e);
                }
                Console.WriteLine(@"Finished processing email alerts.");
                break;
            }
        }
示例#8
0
 public void MoveMessage(string uid, string backupFolder)
 {
     clientImap.MoveMessage(uid, backupFolder);
 }
        public static string Process()
        {
            MailMessage messages = new MailMessage();

            string[] body;

            using (var cliente = new ImapClient("imap.gmail.com", "*****@*****.**", "T0m4s1t0", AuthMethods.Login, 993, true))
            {
                var msj = cliente.SearchMessages(SearchCondition.Unseen()).Where(x => x.Value.Subject.Contains("LEADS")).Where(x => x.Value.Subject.Contains(":"));

                foreach (var id in msj.Select(x => x.Value.Uid))
                {
                    try
                    {
                        string Nombre    = string.Empty;
                        string Correo    = string.Empty;
                        string Telefono1 = string.Empty;
                        string Telefono2 = string.Empty;

                        messages = cliente.GetMessage(id, false, false);

                        string[] salto = new string[] { "\r\n" };
                        body = messages.Body.Replace("Nombre", "").Replace("Correo electrónico", "").Replace("Teléfono 1", "").Replace("Teléfono 2", "").Replace(": ", ":").Replace("________________________________", "").Split(salto, StringSplitOptions.None);

                        for (int i = 0; i < body.Length; i++)
                        {
                            if (body[i].Contains(":"))
                            {
                                if (Nombre == string.Empty)
                                {
                                    Nombre = body[i].Replace(":", "");
                                }
                                else if (Correo == string.Empty)
                                {
                                    Correo = body[i].Replace(":", "");
                                }
                                else if (Telefono1 == string.Empty)
                                {
                                    Telefono1 = body[i].Replace(":", "");
                                }
                                else if (Telefono2 == string.Empty)
                                {
                                    Telefono2 = body[i].Replace(":", "");
                                    break;
                                }
                            }
                        }

                        Dictionary <string, object> Parms = new Dictionary <string, object>();

                        Parms.Add("Nombre", Nombre);
                        Parms.Add("Correo", Correo);
                        Parms.Add("Telefono1", Telefono1);
                        Parms.Add("Telefono2", Telefono2);
                        Parms.Add("Origen", "LeadCorreo");

                        if (messages.Headers["From"].Value.Contains("automate"))
                        {
                            Parms.Add("Fuente", "facebook");
                        }
                        else if (messages.Headers["From"].Value.Contains("mccclictag"))
                        {
                            Parms.Add("Fuente", "clictag");
                        }

                        Parms.Add("Medio", "CPL");

                        char[] array   = messages.Subject.ToCharArray();
                        string camp    = "";
                        bool   campana = false;

                        for (int i = 0; i < array.Length; i++)
                        {
                            if (campana)
                            {
                                camp += array[i];
                            }

                            if (array[i] == ':' && array[i + 1] != ' ')
                            {
                                campana = true;
                                if (array[i + 1] == 'h' && array[i + 2] == '_')
                                {
                                    Parms.Add("Oferta", "Hogares");
                                }
                                else if (array[i + 1] == 'n' && array[i + 2] == '_')
                                {
                                    Parms.Add("Oferta", "Negocios");
                                }
                                else if (array[i + 1] == 'm' && array[i + 2] == '_')
                                {
                                    Parms.Add("Oferta", "Móviles");
                                }
                                else if (array[i + 1] == 'p' && array[i + 2] == '_')
                                {
                                    Parms.Add("Oferta", "Planta");
                                }
                            }
                            else if (!Parms.ContainsKey("Oferta") && array[i + 1] == ' ')
                            {
                                if (array[i + 2] == 'h' && array[i + 3] == '_')
                                {
                                    Parms.Add("Oferta", "Hogares");
                                }
                                else if (array[i + 2] == 'n' && array[i + 3] == '_')
                                {
                                    Parms.Add("Oferta", "Negocios");
                                }
                                else if (array[i + 2] == 'm' && array[i + 3] == '_')
                                {
                                    Parms.Add("Oferta", "Móviles");
                                }
                                else if (array[i + 2] == 'p' && array[i + 3] == '_')
                                {
                                    Parms.Add("Oferta", "Planta");
                                }

                                if (Parms.ContainsKey("Oferta"))
                                {
                                    campana = true;
                                }
                            }
                        }

                        if (!Parms.ContainsKey("Oferta"))
                        {
                            Parms.Add("Oferta", "Otros");
                        }

                        Parms.Add("Campaña", camp);

                        WS_Resources.Resources res = new WS_Resources.Resources();

                        string resultado = res.InsertMail_Agosto(Parms["Nombre"].ToString(), Parms["Correo"].ToString(), Parms["Telefono1"].ToString(), Parms["Telefono2"].ToString(), Parms["Origen"].ToString(), Parms["Fuente"].ToString(), Parms["Medio"].ToString(), Parms["Oferta"].ToString(), Parms["Campaña"].ToString());

                        cliente.MoveMessage(id, "ArchivadosLeader");
                    }
                    catch (Exception ex)
                    {
                        //return ex.Message;
                    }
                }

                return("TODO BIEN");
            }
        }