/// <summary> /// Emails the situation to everyone in the list. /// </summary> private async void EmailSituation() { // Clean the messages. InformationMessage = string.Empty; // Generate the email content based on the template var emailTemplate = new EmailTemplate(ProcessedDate, Lines); var emailTemplateContent = emailTemplate.TransformText(); // Send the mail via Outlook // Check that the email button is disable just after clicking it. IsSendingEmail = true; try { await Task.Run(() => { OutlookApp outlookApp = new OutlookApp(); MailItem mailItem = outlookApp.CreateItem(OlItemType.olMailItem); foreach (var line in Lines) { mailItem.Recipients.Add(line.Person.Email); } mailItem.Recipients.ResolveAll(); mailItem.Subject = String.Format("Soumission des CRA : rapport du {0}", ProcessedDate.ToString("d")); // Images are attached to the mail with a contentId; that way, they will be accessible in the mail // via the attribute "cid". // For instance: <img src="cid:croissantEmpty" /> // In Outlook, this attribute is the property that has the schema name // http://schemas.microsoft.com/mapi/proptag/0x3712001E. var appPath = AppDomain.CurrentDomain.BaseDirectory; Attachment croissantEmptyAttachment = mailItem.Attachments.Add(Path.Combine(appPath, "Assets/croissant_empty.png")); croissantEmptyAttachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E", "croissantEmpty"); Attachment croissantFilledAttachment = mailItem.Attachments.Add(Path.Combine(appPath, "Assets/croissant_filled.png")); croissantFilledAttachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E", "croissantFilled"); Attachment croissantGreyedAttachment = mailItem.Attachments.Add(Path.Combine(appPath, "Assets/croissant_greyed.png")); croissantGreyedAttachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E", "croissantGreyed"); mailItem.HTMLBody = emailTemplateContent; mailItem.Display(false); }); } catch (System.Exception) { InformationMessage = "Erreur lors de la préparation du message"; } IsSendingEmail = false; Save(); }
/// <summary> /// Event handling for the event PenaltyAlreadyExistsAtThisDate. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event arguments.</param> private void HandlePenaltyAlreadyExistsAtThisDate(object sender, EventArgs e) { InformationMessage = String.Format("{0} a déjà une pénalité en date du {1}.", (sender as Line).Person.FirstName, ProcessedDate.ToString("d", CultureInfo.CurrentCulture)); }