public void CheckIfEmailingAttachement_ReturnsResponseMessage() { string nameOfExchangeserver = @"https://outlook.nhs.net/EWS/exchange.asmx"; ModelLoginDetails login = new ModelLoginDetails { Domain = string.Empty, ExchangeServerAddress = @"https://outlook.nhs.net/EWS/exchange.asmx", Password = "", UserName = "******" }; SendEmail send = new SendEmail(login); BodyType type = new BodyType(); type.BodyType1 = BodyTypeType.Text; send.DetailsWithAttachment( new ModelEmailDetails { SubjectOfEmail = "This is the Subject of the Email", BodyOfEmail = "This is the body of the Email", SenderEmail = "*****@*****.**", RecepientEmail = "*****@*****.**", AttachmentLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"GitHub\NhsCommissioningMailer\CommissioningMailer\SampleData\") + "Surgery.csv", BodyType = type, ContentType = "text/comma-separated-values" }); Assert.True(send.ResponseMessage.Contains("NoError")); }
public void oWorker_DoWork(object sender, DoWorkEventArgs e) { Login login = new Login(Settings.Default.LocationOfExchangeServer); login.ShowDialog(); BodyType type = new BodyType(); type.BodyType1 = (BodyTypeType)Enum.Parse(typeof(BodyTypeType), Settings.Default.BodyType); var surgeries = new KeyedEmailAddressRepository(Settings.Default.KeyEmailFilePath).GetAll(); var data = new KeyedDataRepository(_form.KeyedDataFilePath).GetAll(); IEnumerable<DataEmailAddressGroup> _mailerInfo = DataEmailAddressGroup.CreateGroups(surgeries, data); int emailsSent = 0; int totalEmailsToSend = _mailerInfo.SelectMany(recipient => recipient.EmailAddresses).Count(); foreach (DataEmailAddressGroup mailInfo in _mailerInfo) { var attachmentPath = CsvWriter.WriteFile(mailInfo.Data); foreach (var addressee in mailInfo.EmailAddresses) { login.Send.DetailsWithAttachment(new ModelEmailDetails { SubjectOfEmail = string.Format("{0} for {1}", _form.TextBoxSubject, addressee.Key), BodyOfEmail = _form.TextBoxBody, SenderEmail = _form.TextBoxSender, RecepientEmail = addressee.EmailAddress, //AttachmentLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), // @"GitHub\NhsCommissioningMailer\CommissioningMailer\SampleData\") + "KeyEmailAddressPair.csv", AttachmentLocation = attachmentPath.FullName, BodyType = type, ContentType = Settings.Default.ContentType }); double percentage = ((double)emailsSent / totalEmailsToSend) * 100; _oWorker.ReportProgress(Convert.ToInt32(percentage)); emailsSent++; if (_oWorker.CancellationPending) { e.Cancel = true; _oWorker.ReportProgress(0); return; } } } OWorker.ReportProgress(100); }