public void StreamingExchange() { try { Stopwatch watch; long elapsedMs = 0; watch = Stopwatch.StartNew(); _logger.LogInformation(string.Format(LogsProcess.InitProcess, Variables.StreamingExchange, DateTime.Now.ToString())); Exchange.ExchangeService service = new Exchange.ExchangeService(Exchange.ExchangeVersion.Exchange2013); Exchange.WebCredentials wbcred = new Exchange.WebCredentials( _parametersProcessum.GeracaoArquivoEmail.Login, _parametersProcessum.GeracaoArquivoEmail.Senha); service.Credentials = wbcred; service.AutodiscoverUrl(_parametersProcessum.GeracaoArquivoEmail.Login, EWSConnection.RedirectionUrlValidationCallback); EWSConnection.SetStreamingNotifications(service, resetEvent, _parametersProcessum); resetEvent.WaitOne(); watch.Stop(); elapsedMs = watch.ElapsedMilliseconds; _logger.LogInformation(string.Format(LogsProcess.FinishProcess, Variables.StreamingExchange, DateTime.Now.ToString())); _logger.LogInformation(string.Format(LogsProcess.TimeExecution, Variables.StreamingExchange, elapsedMs.ToString())); } catch (Exception ex) { throw ex; } }
/// <summary>TBD</summary> /// <returns>TBD</returns> public static ExchangeService GetService() { Microsoft.Exchange.WebServices.Data.ExchangeService service = new Microsoft.Exchange.WebServices.Data.ExchangeService(); service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SID, ((System.Security.Principal.WindowsIdentity)HttpContext.Current.User.Identity).User.Value); //service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "*****@*****.**"); //service.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; service.Credentials = new WebCredentials("crmExchangeMgr", "St3v13rayv", "titanoutdoor"); service.AutodiscoverUrl(Security.GetUserEmailFromId(Security.GetCurrentUserId)); return service; }
/// <summary> /// Constructor for the communication class. /// <para>The user name is established either automatically if within the domain, or via a dialog box if outside.</para> /// </summary> /// <param name="dad">Pointer back to main window</param> public CommunicationClass(MainWindow dad) { try { service = new EWS.ExchangeService(EWS.ExchangeVersion.Exchange2010_SP1); if (Environment.UserDomainName.Equals("ILLUMINA")) { //Inside, so we'll use our local login credentials service.UseDefaultCredentials = true; userName = Environment.UserName + "@illumina.com"; //Hmmm. Wonder why I have to put this on? service.AutodiscoverUrl(userName, RedirectionUrlValidationCallback); PrincipalContext ctx = new PrincipalContext(ContextType.Domain); UserPrincipal u = UserPrincipal.Current; displayName = u.DisplayName; configFile = "config.xml"; InitQueueList(); initQueueMembers(); initQueue(); } else { //outside, so we'll do a login LoginDialog dlg = new LoginDialog(); dlg.Owner = dad; dlg.ShowDialog(); if (dlg.DialogResult == true) { service.Credentials = new EWS.WebCredentials(dlg.userNameBox.Text, dlg.passwordBox1.Password); service.AutodiscoverUrl(dlg.userNameBox.Text, RedirectionUrlValidationCallback); userName = dlg.userNameBox.Text; //would be nice to get it from service... displayName = userName; initQueue(); } } } catch (Exception e) { Console.WriteLine("{0} Exception caught: ", e); } r = new Random(); // for testing purposes }
//Функция отправки сообщений на Email public Task SendEmail(string GetEmail, string mailSubject, string mailBody) { return(Task.Run(() => { Exchange.ExchangeService service = new Exchange.ExchangeService(); service.Credentials = new NetworkCredential(AppSettings.SendEmail, AppSettings.SendEmailPassword); service.AutodiscoverUrl(AppSettings.SendEmail); Exchange.EmailMessage emailMessage = new Exchange.EmailMessage(service); emailMessage.Body = new Exchange.MessageBody(mailBody); emailMessage.ToRecipients.Add(GetEmail); emailMessage.Send(); })); }
//Функция отправки сообщений на Email public static Task SendEmail(string GetEmail, string itemName) { return(Task.Run(() => { Exchange.ExchangeService service = new Exchange.ExchangeService(); service.Credentials = new NetworkCredential(AppSettings.SendEmail, AppSettings.SendEmailPassword); service.AutodiscoverUrl(AppSettings.SendEmail); Exchange.EmailMessage emailMessage = new Exchange.EmailMessage(service); emailMessage.Subject = "Аукцион #ProКачка - Вы выиграли приз!"; emailMessage.Body = new Exchange.MessageBody("Поздравляем, вы выиграли " + itemName + " на нашем аукционе #ProКачка."); emailMessage.ToRecipients.Add(GetEmail); emailMessage.Send(); })); }
public static Exchange.ExchangeService ConnectToService(User User, Exchange.ITraceListener Listener) { Exchange.ExchangeService oService = default(Exchange.ExchangeService); oService = new Exchange.ExchangeService(Exchange.ExchangeVersion.Exchange2013_SP1); oService.Credentials = new NetworkCredential(User.EmailAddress, User.Password); oService.AutodiscoverUrl(User.EmailAddress, RedirectionUrlValidationCallback); if (Listener != null) { oService.TraceListener = Listener; oService.TraceEnabled = true; oService.TraceFlags = Exchange.TraceFlags.All; } return(oService); }
public List <OutlookAppointment> GetCalendarEntriesInRange() { List <OutlookAppointment> appointments = new List <OutlookAppointment>(); var service = new Microsoft.Exchange.WebServices.Data.ExchangeService(Microsoft.Exchange.WebServices.Data.ExchangeVersion.Exchange2010_SP1); service.Credentials = new Microsoft.Exchange.WebServices.Data.WebCredentials(Settings.Instance.ExchageUser, Settings.Instance.ExchagePassword); if (string.IsNullOrWhiteSpace(Settings.Instance.ExchageServerAddress)) { service.AutodiscoverUrl(Settings.Instance.ExchageUser, ValidateRedirectionUrlCallback); } else { service.Url = new Uri(Settings.Instance.ExchageServerAddress + "/EWS/Exchange.asmx"); } DateTime min = DateTime.Now.AddDays(-Settings.Instance.DaysInThePast); DateTime max = DateTime.Now.AddDays(+Settings.Instance.DaysInTheFuture + 1); var calView = new Microsoft.Exchange.WebServices.Data.CalendarView(min, max); calView.PropertySet = new PropertySet( BasePropertySet.IdOnly, AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.IsRecurring, AppointmentSchema.AppointmentType, AppointmentSchema.End, AppointmentSchema.IsAllDayEvent, AppointmentSchema.Location, AppointmentSchema.Organizer, AppointmentSchema.ReminderMinutesBeforeStart, AppointmentSchema.IsReminderSet ); FindItemsResults <Appointment> findResults = service.FindAppointments(WellKnownFolderName.Calendar, calView); foreach (Appointment appointment in findResults.Items) { OutlookAppointment newAppointment = GetOutlookAppointment(appointment, service); appointments.Add(newAppointment); } return(appointments); }
public List<OutlookAppointment> GetCalendarEntriesInRange() { List<OutlookAppointment> appointments = new List<OutlookAppointment>(); var service = new Microsoft.Exchange.WebServices.Data.ExchangeService(Microsoft.Exchange.WebServices.Data.ExchangeVersion.Exchange2010_SP1); service.Credentials = new Microsoft.Exchange.WebServices.Data.WebCredentials(Settings.Instance.ExchageUser, Settings.Instance.ExchagePassword); if (string.IsNullOrWhiteSpace(Settings.Instance.ExchageServerAddress)) { service.AutodiscoverUrl(Settings.Instance.ExchageUser, ValidateRedirectionUrlCallback); } else { service.Url = new Uri(Settings.Instance.ExchageServerAddress + "/EWS/Exchange.asmx"); } DateTime min = DateTime.Now.AddDays(-Settings.Instance.DaysInThePast); DateTime max = DateTime.Now.AddDays(+Settings.Instance.DaysInTheFuture + 1); var calView = new Microsoft.Exchange.WebServices.Data.CalendarView(min, max); calView.PropertySet = new PropertySet( BasePropertySet.IdOnly, AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.IsRecurring, AppointmentSchema.AppointmentType, AppointmentSchema.End, AppointmentSchema.IsAllDayEvent, AppointmentSchema.Location, AppointmentSchema.Organizer, AppointmentSchema.ReminderMinutesBeforeStart, AppointmentSchema.IsReminderSet ); FindItemsResults<Appointment> findResults = service.FindAppointments(WellKnownFolderName.Calendar, calView); foreach (Appointment appointment in findResults.Items) { OutlookAppointment newAppointment = GetOutlookAppointment(appointment, service); appointments.Add(newAppointment); } return appointments; }
private static webServiceData.ExchangeService getWebService(SchedulingInfo schedulingInfo){ long now = DateTime.UtcNow.Ticks; RvLogger.DebugWrite("start to create webservice======================================"); ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack; webServiceData.ExchangeService service = new webServiceData.ExchangeService(webServiceData.ExchangeVersion.Exchange2010_SP2); String userAccount = null; if (settingsInfo.ContainsKey("ExchangeServer.email.account")) userAccount = settingsInfo["ExchangeServer.email.account"]; if(settingsInfo.ContainsKey("ExchangeServer.user.account")) userAccount = settingsInfo["ExchangeServer.user.account"]; String userPassword = null; if (settingsInfo.ContainsKey("ExchangeServer.email.password")) userPassword = settingsInfo["ExchangeServer.email.password"]; if (settingsInfo.ContainsKey("ExchangeServer.user.password")) userPassword = settingsInfo["ExchangeServer.user.password"]; String userEmail = null; if (settingsInfo.ContainsKey("ExchangeServer.email.account")) userEmail = settingsInfo["ExchangeServer.email.account"]; if (settingsInfo.ContainsKey("ExchangeServer.user.email")) userEmail = settingsInfo["ExchangeServer.user.email"]; RvLogger.DebugWrite("EXCHANGE_USER: "******"EXCHANGE_EMAIL: " + userEmail); RvLogger.DebugWrite("EXCHANGE_password: "******"AutodiscoverUrl Error: " + e.Message); RvLogger.InfoWrite(e.StackTrace); service.TraceEnabled = true; service.TraceListener = new TraceListener(); service.TraceFlags = webServiceData.TraceFlags.All; try { service.AutodiscoverUrl(userEmail, RedirectionUrlValidationCallback); } catch (Exception e1) { RvLogger.InfoWrite("AutodiscoverUrl Error1: " + e1.Message); RvLogger.InfoWrite(e1.StackTrace); if (settingsInfo.ContainsKey("ExchangeServer.ewsurl")) { String ewsurl = settingsInfo["ExchangeServer.ewsurl"]; service.Url = new Uri(ewsurl); } if (settingsInfo.ContainsKey("ExchangeServer.trace.all")) { String traceAll = settingsInfo["ExchangeServer.trace.all"]; if (traceAll != null && !traceAll.Equals("true")) { service.TraceEnabled = false; service.TraceListener = null; } } } } RvLogger.DebugWrite("Discovered service URL:"+service.Url); if (null != schedulingInfo) service.ImpersonatedUserId = new webServiceData.ImpersonatedUserId(webServiceData.ConnectingIdType.SmtpAddress, schedulingInfo.delegatorEmailAddr); RvLogger.DebugWrite("Finished to create webservice======================================time:" + (DateTime.UtcNow.Ticks - now)); return service; }
private static async Task <bool> SendByExchangeAsync(EmailNetConfiguration emailConfig) { Exchange.ExchangeService service = new Exchange.ExchangeService(emailConfig.EmailExchange.ExchangeVersion); service.Credentials = new NetworkCredential(emailConfig.Username, emailConfig.Password); if (emailConfig.EmailExchange.IsTraceEnabled) { service.TraceEnabled = true; service.TraceFlags = emailConfig.EmailExchange.TraceFlags; } service.AutodiscoverUrl(emailConfig.EmailAddress.FromEmail, RedirectionUrlValidationCallback); Exchange.EmailMessage message = new Exchange.EmailMessage(service); message.Subject = emailConfig.Subject; message.Body = new Exchange.MessageBody(emailConfig.Body.Value); emailConfig.To.ForEach(to => message.ToRecipients.Add(new Exchange.EmailAddress(to.FromEmail))); if (emailConfig.Bcc?.Count > 0) { emailConfig.Bcc.ForEach(bcc => message.BccRecipients.Add(new Exchange.EmailAddress(bcc.FromEmail))); } if (emailConfig.Cc?.Count > 0) { emailConfig.Cc.ForEach(cc => message.CcRecipients.Add(new Exchange.EmailAddress(cc.FromEmail))); } if (emailConfig.Attachement.IsAttachement) { Utils.IsDirectoryExistsThrowException(emailConfig.Attachement.AttachementPathDirectory); if (emailConfig.Zip.IsCompressed) { Utils.ZipFiles(emailConfig.Attachement.AttachementPathDirectory, emailConfig.Zip.ZipPathDirectory, emailConfig.Zip.IsDelete); var file = Utils.ReadAllBytes(emailConfig.Zip.ZipPathDirectory).FirstOrDefault(); message.Attachments.AddFileAttachment(file.filename); if (emailConfig.Zip.IsDelete) { Utils.DeleteFilesDirectory(emailConfig.Zip.ZipPathDirectory, true); } } else { foreach (var file in Utils.ReadAllBytes(emailConfig.Attachement.AttachementPathDirectory)) { message.Attachments.AddFileAttachment(file.filename); } } } Utils.Show($"\nEnviando email con {nameof(EmailNetService)}..."); await message.Save(); await message.SendAndSaveCopy(); return(await Task.FromResult(true)); }