Ejemplo n.º 1
0
 ///<summary></summary>
 public FormEmailMessageEdit(EmailMessage messageCur)
 {
     InitializeComponent();            // Required for Windows Form Designer support
     //PatNum=patNum;
     Lan.F(this);
     MessageCur = messageCur.Copy();
     listAttachments.ContextMenu = contextMenuAttachments;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Copies a single item between folders in a call to EWS.
        /// </summary>
        /// <param name="service">An ExchangeService object with credentials and the EWS URL.</param>
        private static void CopyAnItem(ExchangeService service)
        {
            // Create two items to copy. You can copy any item type in your Exchange mailbox.
            // You will need to save these items to your Exchange mailbox before they can be copied.
            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.");

            Collection <EmailMessage> messages = new 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 make a copy.
                ServiceResponseCollection <ServiceResponse> responses = service.CreateItems(messages, WellKnownFolderName.Drafts, MessageDisposition.SaveOnly, null);

                if (responses.OverallResult == ServiceResult.Success)
                {
                    Console.WriteLine("Successfully created items that we will copy.");
                }
                else
                {
                    throw new Exception("The batch creation of the email message draft items was not successful.");
                }
            }
            catch (ServiceResponseException ex)
            {
                Console.WriteLine("Error: {0}", ex.Message);
            }

            try
            {
                // You can create copies of a single item. This will result in a CopyItem operation call to EWS.
                // The EmailMessage that is returned is a copy of the item with its own unique identifier. The email message to copy
                // must be saved on the server before you can copy it.
                EmailMessage email3 = email1.Copy(WellKnownFolderName.DeletedItems) as EmailMessage;
            }

            catch (ServiceResponseException ex)
            {
                Console.WriteLine("Error: {0}", ex.Message);
            }
        }
Ejemplo n.º 3
0
        public void StuffFolders(int[] labels)
        {
            try
            {
                for (int i = 0; i < documents.Length; i++)
                {
                    string subj = documents[i];


                    int    folderAssign = labels[i];
                    string folderName   = "unlabeled - " + folderAssign.ToString();
                    // Ceate an email message and identify the Exchange service.
                    EmailMessage message = new EmailMessage(ExchangeServices.exchange);

                    //// Add properties to the email message.
                    message.Subject = subj.ToString();


                    // set View
                    FolderView view = new FolderView(100);
                    view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
                    view.PropertySet.Add(FolderSchema.DisplayName);
                    view.Traversal = FolderTraversal.Deep;

                    FindFoldersResults findFolderResults = ExchangeServices.exchange.FindFolders(WellKnownFolderName.Inbox, view);
                    Folder             F = new Folder(ExchangeServices.exchange);
                    // find specific folder
                    foreach (Folder f in findFolderResults)
                    {
                        // show FolderId of the folder "Test"
                        if (f.DisplayName == folderName)
                        {
                            F = f;
                            message.Save();
                            // Copy the orignal message into another folder in the mailbox and store the returned item.
                            message.Copy(F.Id);
                        }
                        else
                        {
                        }
                    }
                }
            }
            catch (ServiceResponseException sre) { System.Diagnostics.Debug.WriteLine(sre.ToString()); }
        }
Ejemplo n.º 4
0
        //gavdcodeend 08

        //gavdcodebegin 09
        static void CopyOneEmail(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 emailToCopy = EmailMessage.Bind(ExService, myEmailId, myPropSet);

            emailToCopy.Copy(WellKnownFolderName.Drafts);
        }
Ejemplo n.º 5
0
        private void sendMessage(EmailMessage message)
        {
            if (ParameterSetName == "existingEmail")
            {
                message = (EmailMessage)message.Copy(WellKnownFolderName.Drafts);

                EmailAddressCollection toRecipients  = message.ToRecipients;
                EmailAddressCollection ccRecipients  = message.CcRecipients;
                EmailAddressCollection bccRecipients = message.BccRecipients;
                for (int i = toRecipients.Count - 1; i >= 0; i--)
                {
                    message.ToRecipients.Remove(toRecipients[i]);
                }
                for (int i = ccRecipients.Count - 1; i >= 0; i--)
                {
                    message.ToRecipients.Remove(ccRecipients[i]);
                }
                for (int i = bccRecipients.Count - 1; i >= 0; i--)
                {
                    message.ToRecipients.Remove(bccRecipients[i]);
                }
            }
            // Setup Recipients
            foreach (string recipient in Recipients)
            {
                message.ToRecipients.Add(recipient);
            }
            if (BCCRecipients != null)
            {
                foreach (string recipient in BCCRecipients)
                {
                    message.BccRecipients.Add(recipient);
                }
            }
            if (CCRecipients != null)
            {
                foreach (string recipient in CCRecipients)
                {
                    message.CcRecipients.Add(recipient);
                }
            }

            if (Subject != null)
            {
                message.Subject = Subject;
            }
            if (Body != null)
            {
                MessageBody body = new MessageBody(bodyFormat, Body); message.Body = body;
            }

            if (attachments != null)
            {
                foreach (FileInfo attachLocation in attachments)
                {
                    if (attachLocation.Exists)
                    {
                        message.Attachments.AddFileAttachment(attachLocation.FullName);
                    }
                }
            }
            message.Importance = ImportanceLevel;

            if (RequestReadResponse.IsPresent)
            {
                message.IsReadReceiptRequested = true;
            }
            if (RequestResponse.IsPresent)
            {
                message.IsResponseRequested = true;
            }
            if (RequestDeliveryReceipt.IsPresent)
            {
                message.IsDeliveryReceiptRequested = true;
            }

            message.SendAndSaveCopy();
        }