private void btnMoveToFolder_Click(object sender, EventArgs e) { if (this.treeViewFolder.SelectedNode == null) { MessageBox.Show("Select a folder under Inbox firstly."); return; } if (this.listViewMail.Visible && this.listViewMail.SelectedItems.Count > 0) { ItemId itemId = new ItemId(this.listViewMail.SelectedItems[0].SubItems[4].Text); EmailMessage em = EmailMessage.Bind(service, itemId); if (this.treeViewFolder.SelectedNode.Name == em.ParentFolderId.UniqueId) { MessageBox.Show("This folder is the same folder of mail, select another folder."); return; } else { em.Move(new FolderId(this.treeViewFolder.SelectedNode.Name)); this.txtLog.Text += "Move mail into folder success\r\nEWS API: Move\r\nLocation:..\\EWS\\EWS\\Form1.cs(379)\r\n\r\n"; getMails(this.treeViewFolder.SelectedNode.Name, null); } } else { MessageBox.Show("Select a mail firstly"); initialMailListView(); return; } }
public bool MoveEmailItemInOutlook(EmailMessage message, Entity.Store store) { //var forwardEmail = this.CreateDraftEmail(message, store); Item movedMessage; switch (store.Program) { case Enum.ProgramTypes.None: case Enum.ProgramTypes.Generic: break; case Enum.ProgramTypes.NewStores: movedMessage = message.Move(this.rfiNewStoresFolder); //this.ArchiveAnsweredRfi(movedMessage, store); break; case Enum.ProgramTypes.TakeOvers: case Enum.ProgramTypes.Resturants: case Enum.ProgramTypes.Expansions: case Enum.ProgramTypes.Special: case Enum.ProgramTypes.DallasCommunityCollege: case Enum.ProgramTypes.ABRHoldings: case Enum.ProgramTypes.Express: movedMessage = message.Move(this.rfiExistingStoresFolder); //this.ArchiveAnsweredRfi(movedMessage, store); break; case Enum.ProgramTypes.FuelStations: case Enum.ProgramTypes.Remodels: movedMessage = message.Move(this.rfiRemodelFolder); break; default: throw new Exception("Invalid value for ProgramTypes"); } return(false); }
public void MoveProcessedMessage(EmailMessage message, ExchangeService serviceInfo) { ExchangeService service = serviceInfo; FindFoldersResults folderResults = service.FindFolders(WellKnownFolderName.Inbox, new FolderView(int.MaxValue)); message.IsRead = true; message.Update(ConflictResolutionMode.AlwaysOverwrite); message.Move(folderResults.Folders[0].Id); }
public void ArchiveMessage(EmailMessage message) { FindFoldersResults ArchiveFolder = service.FindFolders(WellKnownFolderName.MsgFolderRoot, new SearchFilter.IsEqualTo(FolderSchema.DisplayName, "Archive"), new FolderView(1)); if (ArchiveFolder.Folders.Count == 1) { message.Move(ArchiveFolder.Folders[0].Id); } }
} // End Sub FindUnreadEmail public static void MoveMessage(ExchangeService service) { // Create two items to be moved. You can move any item type in your Exchange mailbox. // You will need to save these items to your Exchange mailbox before they can be moved. EmailMessage email1 = new EmailMessage(service); email1.Subject = "Draft email one"; email1.Body = new MessageBody(BodyType.Text, "Draft body of the mail."); EmailMessage email2 = new EmailMessage(service); email2.Subject = "Draft email two"; email1.Body = new MessageBody(BodyType.Text, "Draft body of the mail."); System.Collections.ObjectModel.Collection <EmailMessage> messages = new System.Collections.ObjectModel.Collection <EmailMessage>(); messages.Add(email1); messages.Add(email2); try { // This results in a CreateItem operation call to EWS. The items are created on the server. // The response contains the item identifiers of the newly created items. The items on the client // now have item identifiers, which you need in order to move the item. ServiceResponseCollection <ServiceResponse> responses = service.CreateItems(messages, WellKnownFolderName.Drafts, MessageDisposition.SaveOnly, null); if (responses.OverallResult == ServiceResult.Success) { System.Console.WriteLine("Successfully created items to be copied."); } else { throw new System.Exception("The batch creation of the email message draft items was not successful."); } } catch (ServiceResponseException ex) { System.Console.WriteLine("Error: {0}", ex.Message); } try { // You can move a single item. This will result in a MoveItem operation call to EWS. // The EmailMessage that is returned is the item with its updated item identifier. You must save the email // message to the server before you can move it. EmailMessage email3 = email1.Move(WellKnownFolderName.DeletedItems) as EmailMessage; } catch (ServiceResponseException ex) { System.Console.WriteLine("Error: {0}", ex.Message); } } // End Sub MoveMessage
protected static void MoveMessageToTestFolder(string subject) { EmailMessage message = null; while (message == null) { message = exchangeService.FindItems( WellKnownFolderName.Inbox, new SearchFilter.ContainsSubstring(ItemSchema.Subject, subject), new ItemView(1)).FirstOrDefault() as EmailMessage; } message.Move(testFolder.Id as FolderId); }
private bool sendToOtherFolder(string uniqueIdentifier, string folderName, FolderId folderId) { try { PropertySet propSet = new PropertySet(BasePropertySet.IdOnly, ItemSchema.Subject, ItemSchema.ParentFolderId); EmailMessage beforeMessage = EmailMessage.Bind(_exchangeService, new ItemId(uniqueIdentifier), propSet); Item item = beforeMessage.Move(folderId); EmailMessage movedMessage = EmailMessage.Bind(_exchangeService, item.Id, propSet); } catch (Exception ex) { _logger.Error($"Could not move Email {uniqueIdentifier} to folder {folderName}", ex); return(false); } return(true); }
public void MoverEmailInbox(ExchangeService service, EmailMessage mail) { try { Folder rootfolder = Folder.Bind(service, WellKnownFolderName.Inbox); rootfolder.Load(); Folder foundFolder = rootfolder.FindFolders(new FolderView(100)).FirstOrDefault(x => x.DisplayName == "BRT"); if (foundFolder == default(Folder)) { throw new DirectoryNotFoundException(string.Format("Não foi possível encontrar a pasta {0}.", "BRT")); } mail.Move(foundFolder.Id); } catch (Exception ex) { Console.WriteLine(ex); } }
private static void ProcessEmailAsInvalid(EmailMessage email, string mailboxMonitorAddress, FolderId invalidMailFolderId) { //forward for debugging LoggingManager.WriteToLog("Processing Mail", "Forwarding with body", "Invalid"); MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Forwarding with body", "Invalid")); email.Forward(new MessageBody(BodyType.HTML, "INVALID?"), new EmailAddress[1] { mailboxMonitorAddress }); LoggingManager.WriteToLog("Processing Mail", "Forwarded with body", "Invalid"); MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Forwarding with body", "Invalid")); email.IsRead = true; email.Update(ConflictResolutionMode.AlwaysOverwrite); LoggingManager.WriteToLog("Processing Mail", "Email marked as", "Unread"); MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Marked as", "Unread")); //move mail to processed folder email.Move(invalidMailFolderId); LoggingManager.WriteToLog("Processing Mail", "Email moved to", "Invalid"); MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Email moved to", "Invalid")); }
/// <summary> /// Logic for moving mails /// </summary> /// <param name="context"></param> protected override void Execute(CodeActivityContext context) { // ****************** getting the input values ************************ ExchangeService objExchangeService = ObjExchangeService.Get(context); Item mail = Mail.Get(context); string mailboxName = MailboxName.Get(context); string folderName = FolderName.Get(context); //********** Logic to move a mail from a folder to another ************ FolderView view = new FolderView(10000); view.PropertySet = new PropertySet(BasePropertySet.IdOnly); view.PropertySet.Add(FolderSchema.DisplayName); view.Traversal = FolderTraversal.Deep; Mailbox mailbox = new Mailbox(mailboxName); FindFoldersResults findFolderResults = objExchangeService.FindFolders(new FolderId(WellKnownFolderName.MsgFolderRoot, mailbox), view); bool flag = false; foreach (Folder folder in findFolderResults) { //Searching for supplied folder into mailbox if (folder.DisplayName.Equals(folderName)) { PropertySet propSet = new PropertySet(BasePropertySet.IdOnly, EmailMessageSchema.Subject, EmailMessageSchema.ParentFolderId); // Bind to the existing item by using the ItemId. EmailMessage beforeMessage = EmailMessage.Bind(objExchangeService, mail.Id, propSet); // Move the specified mail to the given folder beforeMessage.Move(folder.Id); flag = true; break; } } if (!flag) { throw new Exception("Supplied folder is not found"); } }
//gavdcodeend 07 //gavdcodebegin 08 static void MoveOneEmail(ExchangeService ExService) { SearchFilter myFilter = new SearchFilter.SearchFilterCollection( LogicalOperator.And, new SearchFilter.IsEqualTo( EmailMessageSchema.Subject, "Email created by EWS")); ItemView myView = new ItemView(1); FindItemsResults <Item> findResults = ExService.FindItems( WellKnownFolderName.Inbox, myFilter, myView); ItemId myEmailId = null; foreach (Item oneItem in findResults) { myEmailId = oneItem.Id; } PropertySet myPropSet = new PropertySet(BasePropertySet.IdOnly, EmailMessageSchema.Subject, EmailMessageSchema.ParentFolderId); EmailMessage emailToMove = EmailMessage.Bind(ExService, myEmailId, myPropSet); emailToMove.Move(WellKnownFolderName.JunkEmail); }
public void Execute(IActivityRequest request, IActivityResponse response) { userName = settings.UserName; password = settings.Password; domain = settings.Domain; serviceURL = settings.ServiceUrl; exchangeVersion = settings.ExchangeVersion; emailID = request.Inputs["Email ID"].AsString(); destinationFolder = request.Inputs["Destination Folder"].AsString(); string alternateMailbox = string.Empty; if (request.Inputs.Contains("Alternate Mailbox")) { alternateMailbox = request.Inputs["Alternate Mailbox"].AsString(); } ExchangeService service = new ExchangeService(); switch (exchangeVersion) { case "Exchange2007_SP1": service = new ExchangeService(ExchangeVersion.Exchange2007_SP1); break; case "Exchange2010": service = new ExchangeService(ExchangeVersion.Exchange2010); break; case "Exchange2010_SP1": service = new ExchangeService(ExchangeVersion.Exchange2010_SP1); break; default: service = new ExchangeService(); break; } service.Credentials = new WebCredentials(userName, password, domain); String AccountUrl = userName + "@" + domain; if (serviceURL.Equals("Autodiscover")) { service.AutodiscoverUrl(AccountUrl, (a) => { return(true); }); } else { service.Url = new Uri(serviceURL); } if (!alternateMailbox.Equals(String.Empty)) { service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, alternateMailbox); } EmailMessage message = EmailMessage.Bind(service, emailID); if (!destinationFolder.Equals(String.Empty)) { SearchFilter filter = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, destinationFolder); FolderView view = new FolderView(int.MaxValue); view.PropertySet = new PropertySet(BasePropertySet.IdOnly); view.PropertySet.Add(FolderSchema.DisplayName); view.Traversal = FolderTraversal.Deep; FindFoldersResults results = service.FindFolders(WellKnownFolderName.MsgFolderRoot, filter, view); foreach (Folder folder in results) { message = (EmailMessage)message.Move(folder.Id); if (message != null) { response.Publish("Email ID", message.Id); } else { response.Publish("Email ID", "Email moved between two mailboxes or between a mailbox and a public folder"); } break; } } }
public Item MoveMessage(FolderId destination) { return(_message.Move(destination)); }
private static bool ProcessEmailAttachments(EmailMessage email, string mailboxMonitorAddress, FolderId moveMailFolderId, long savedMySQLMessageId) { if (email.Attachments.Count > 0) { foreach (var emailAttachment in email.Attachments.Where(a => a.Name.ToLower().EndsWith("lic"))) { if (emailAttachment is FileAttachment) { var emailFileAttachment = emailAttachment as FileAttachment; emailFileAttachment.Load(); var utfDecodedContent = Encoding.UTF8.GetString(emailFileAttachment.Content); if (utfDecodedContent.Contains("---")) { Atum.DAL.Managers.LoggingManager.WriteToLog("Processing Mail", "From", email.Sender.Address); MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "From", email.Sender.Address)); Atum.DAL.Managers.LoggingManager.WriteToLog("Processing Mail", "Start of license block", "Found"); MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Start of license block", "Found")); var activatedLicenseFile = Atum.DAL.Licenses.OnlineCatalogLicenses.FromLicenseStream(utfDecodedContent); if (activatedLicenseFile.Count == 1) { LoggingManager.WriteToLog("Processing Mail", "License Object", "Processed"); MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "License Object", "Processed")); //debug (use forwarding to monitor registration process) email.Forward(new MessageBody(BodyType.HTML, "Done?"), new EmailAddress[1] { mailboxMonitorAddress }); LoggingManager.WriteToLog("Processing Mail", "Forwarding with body", "Done"); MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Forwarding with body", "Done")); //prepare var emailReply = new StringBuilder(); if (email.Body.BodyType == BodyType.HTML) { emailReply.AppendLine("Dear customer, <br/><br/>Thank you for requesting an activation code.<br/><br/>"); } else { emailReply.AppendLine("Dear customer,"); emailReply.AppendLine("Thank you for requesting an activation code."); emailReply.AppendLine(); emailReply.AppendLine(); } //activate license activatedLicenseFile[0].Activated = true; activatedLicenseFile[0].ExpirationDate = DateTime.Now.AddYears(1); activatedLicenseFile[0].ActivationDate = DateTime.Now; activatedLicenseFile[0].LicenseType = Atum.DAL.Licenses.AvailableLicense.TypeOfLicense.StudioStandard; var emailFileAttachmentName = emailFileAttachment.Name; var emailFileAttachmentNameActivated = emailFileAttachment.Name.Substring(0, emailFileAttachment.Name.LastIndexOf(".")); emailFileAttachmentNameActivated += "-activated.lic"; var replyMessage = email.CreateReply(true); replyMessage.BodyPrefix = emailReply.ToString(); EmailMessage replyEmailMessage = replyMessage.Save(); replyEmailMessage.Attachments.AddFileAttachment(emailFileAttachmentNameActivated, Encoding.UTF8.GetBytes(activatedLicenseFile.ToLicenseRequest())); replyEmailMessage.Update(ConflictResolutionMode.AutoResolve); replyEmailMessage.Send(); LoggingManager.WriteToLog("Processing Mail", "Forwarded with body", "Done"); MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Forwarding with body", "Done")); //mark as read email.IsRead = true; email.Update(ConflictResolutionMode.AlwaysOverwrite); LoggingManager.WriteToLog("Processing Mail", "Email marked as", "Unread"); MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Email marked as", "Unread")); //save to database MsSqlManager.UpdateRAWMessageWithActivationCode(savedMySQLMessageId, activatedLicenseFile); //move mail to processed folder email.Move(moveMailFolderId); LoggingManager.WriteToLog("Processing Mail", "Email moved to", "Processed"); MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Email moved to", "Processed")); //save to path var atumLicenseFile = new AtumEmailLicenseRequest(email.Sender.Address, email.DateTimeReceived, activatedLicenseFile[0]); atumLicenseFile.Save(); LoggingManager.WriteToLog("Processing Mail", "Email moved to", "Processed"); MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Email moved to", "Processed")); } } } } return(true); } return(false); }
private static bool ProcessEmailBodyText(EmailMessage email, string mailboxMonitorAddress, FolderId moveMailFolderId, long savedMySQLMessageId) { if (email.Body.Text.Contains("---StartOfLicenseCode---")) { Atum.DAL.Managers.LoggingManager.WriteToLog("Processing Mail", "From", email.Sender.Address); Atum.DAL.Managers.LoggingManager.WriteToLog("Processing Mail", "Start of license block", "Found"); var emailBodyAsHtml = email.Body.Text; var emailBodyText = emailBodyAsHtml.Substring(emailBodyAsHtml.IndexOf("---StartOfLicenseCode---")); var endLicenseTag = "---EndofLicenseCode---"; emailBodyText = emailBodyText.Substring(0, emailBodyText.IndexOf(endLicenseTag) + endLicenseTag.Length); emailBodyText = Regex.Replace(emailBodyText, "<.*?>", string.Empty); //strip HTML tags emailBodyText = WebUtility.HtmlDecode(emailBodyText); //convert html encoding to text encoding var licenseFile = Atum.DAL.Licenses.OnlineCatalogLicenses.FromLicenseStream(emailBodyText); if (licenseFile.Count == 1) { LoggingManager.WriteToLog("Processing Mail", "License Object", "Processed"); //debug (use forwarding to monitor registration process) email.Forward(new MessageBody(BodyType.HTML, "Done?"), new EmailAddress[1] { mailboxMonitorAddress }); MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Forwarding with body", "Done")); LoggingManager.WriteToLog("Processing Mail", "Forwarding with body", "Done"); //preprare var emailReply = new StringBuilder(); if (email.Body.BodyType == BodyType.HTML) { emailReply.AppendLine("Dear customer, <br/><br/>Thank you for requesting an activation code.<br/><br/>"); } else { emailReply.AppendLine("Dear customer,"); emailReply.AppendLine("Thank you for requesting an activation code."); emailReply.AppendLine(); emailReply.AppendLine(); } //activate license licenseFile[0].Activated = true; licenseFile[0].ExpirationDate = DateTime.Now.AddYears(1); licenseFile[0].ActivationDate = DateTime.Now; licenseFile[0].LicenseType = Atum.DAL.Licenses.AvailableLicense.TypeOfLicense.StudioStandard; emailReply.AppendLine(licenseFile.ToLicenseRequest()); email.Reply(new MessageBody(email.Body.BodyType, emailReply.ToString()), true); MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Forwarding with body", "Done")); LoggingManager.WriteToLog("Processing Mail", "Forwarded with body", "Done"); //mark as read email.IsRead = true; email.Update(ConflictResolutionMode.AlwaysOverwrite); LoggingManager.WriteToLog("Processing Mail", "Email marked as", "Unread"); MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Email marked as", "Unread")); //save to database MsSqlManager.UpdateRAWMessageWithActivationCode(savedMySQLMessageId, licenseFile); //move mail to processed folder email.Move(moveMailFolderId); LoggingManager.WriteToLog("Processing Mail", "Email moved to", "Processed"); MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Email moved to", "Processed")); //save to path var atumLicenseFile = new AtumEmailLicenseRequest(email.Sender.Address, email.DateTimeReceived, licenseFile[0]); atumLicenseFile.Save(); LoggingManager.WriteToLog("Processing Mail", "Email moved to", "Processed"); MsSqlManager.SaveLogging(new DAL.Logging.LoggingInfo(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), "Processing Mail", "Email moved to", "Processed")); } return(true); } return(false); }