Exemple #1
0
        public void TestSaveAttachmentsToEmptyFolder()
        {
            var directory = new System.IO.DirectoryInfo(System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory));

            var store = new RfiCoder.Entity.Store();

            store.ProjectNumber = 1305015;

            store.Program = RfiCoder.Enum.ProgramTypes.NewStores;

            store.City = "Oconomowoc";

            var fileHandler = new RfiCoder.Utilities.FileHandler(store);

            var email = new Microsoft.Exchange.WebServices.Data.EmailMessage(
                RfiCoder.Utilities.EmailHelper.InstanceOf.GetEmailService);

            email.Subject = @"WM Store #9999 Sink Drain Dimensions RFI";

            var files = directory.GetFiles();

            var randGen = new System.Random();

            var pt = randGen.Next(1, files.Length);

            var file = files[pt];

            email.Attachments.AddFileAttachment(file.Name, file.OpenRead());

            email.Save(Microsoft.Exchange.WebServices.Data.WellKnownFolderName.Drafts);

            var result = fileHandler.SaveAttachmentsToFolder(email.Attachments);

            email.Delete(Microsoft.Exchange.WebServices.Data.DeleteMode.HardDelete);
        }
Exemple #2
0
        public void TestSaveAttachmentsAndEmail()
        {
            int i = 0;

            var directory = new System.IO.DirectoryInfo(System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory));

            var store = new RfiCoder.Entity.Store();

            store.ProjectNumber = 1305015;

            store.Program = RfiCoder.Enum.ProgramTypes.NewStores;

            store.City = "Oconomowoc";

            do
            {
                var email = new Microsoft.Exchange.WebServices.Data.EmailMessage(
                    RfiCoder.Utilities.EmailHelper.InstanceOf.GetEmailService);

                email.Subject = @"FW: RFI:Request for Information Answered: TEST";

                email.Categories.Add("TEST");

                var files = directory.GetFiles();

                var randGen = new System.Random();

                var pt = randGen.Next(1, files.Length);

                var file = files[pt];

                email.Attachments.AddFileAttachment(file.Name, file.OpenRead());

                email.Save(RfiCoder.Utilities.EmailHelper.InstanceOf.NewStoresFolder);

                i++;
            } while (i < 5);

            var itemView = new Microsoft.Exchange.WebServices.Data.ItemView(int.MaxValue);

            itemView.PropertySet = new Microsoft.Exchange.WebServices.Data.PropertySet(Microsoft.Exchange.WebServices.Data.BasePropertySet.IdOnly, Microsoft.Exchange.WebServices.Data.ItemSchema.Categories);

            var filter = new Microsoft.Exchange.WebServices.Data.SearchFilter.IsEqualTo(Microsoft.Exchange.WebServices.Data.EmailMessageSchema.Categories, "TEST");

            var results = RfiCoder.Utilities.EmailHelper.InstanceOf.GetEmailService.FindItems(RfiCoder.Utilities.EmailHelper.InstanceOf.NewStoresFolder, filter, itemView);

            var message = Microsoft.Exchange.WebServices.Data.Item.Bind(RfiCoder.Utilities.EmailHelper.InstanceOf.GetEmailService,
                                                                        results.Items[0].Id,
                                                                        RfiCoder.Utilities.EmailHelper.EmailProperties
                                                                        );

            var result = RfiCoder.Utilities.EmailHelper.InstanceOf.ArchiveAnsweredRfi(message, store);

            Assert.That(result, Is.True);
        }
Exemple #3
0
        public void TestSaveAttachmentsToFolderWithDuplicateFile()
        {
            var store = new RfiCoder.Entity.Store();

            store.ProjectNumber = 1304007;

            store.Program = RfiCoder.Enum.ProgramTypes.NewStores;

            store.City = "Austin (lakeline)";

            var fileHandler = new RfiCoder.Utilities.FileHandler(store);

            var email = new Microsoft.Exchange.WebServices.Data.EmailMessage(
                RfiCoder.Utilities.EmailHelper.InstanceOf.GetEmailService);

            email.Subject = @"WM Store #9999 Sink Drain Dimensions RFI";

            var directory = new System.IO.DirectoryInfo(fileHandler.Path);

            var files = directory.GetFiles();

            var randGen = new System.Random();

            var pt = randGen.Next(1, files.Length);

            var file = files[pt];

            email.Attachments.AddFileAttachment(file.Name, file.OpenRead());

            email.Save(Microsoft.Exchange.WebServices.Data.WellKnownFolderName.Drafts);

            var result = fileHandler.SaveAttachmentsToFolder(email.Attachments);

            email.Delete(Microsoft.Exchange.WebServices.Data.DeleteMode.HardDelete);

            Assert.That(result, Is.False);
        }
        private Task SendMailAsync(string subject, string body, IReadOnlyList <string> toRecipients, IReadOnlyList <string> ccRecipients = null, IDictionary <string, byte[]> attachments = null)
        {
            return(Task.Run(() =>
            {
                var message = new Microsoft.Exchange.WebServices.Data.EmailMessage(exchangeSvc);

                foreach (string toRecipient in toRecipients)
                {
                    message.ToRecipients.Add(NormailizeEmailRecipient(toRecipient));
                }

                if (ccRecipients != null)
                {
                    foreach (string ccRecipient in ccRecipients)
                    {
                        message.CcRecipients.Add(NormailizeEmailRecipient(ccRecipient));
                    }
                }

                message.Subject = subject;
                message.Body = body;

                if (attachments != null)
                {
                    foreach (var attachment in attachments)
                    {
                        var fileAttachment = message.Attachments.AddFileAttachment(attachment.Key, attachment.Value);
                        fileAttachment.IsInline = true;
                        fileAttachment.ContentId = attachment.Key;
                    }
                }

                message.Save();
                message.Send();
            }));
        }