diff --git a/Project/Send_MailKitMessage.cs b/Project/Send_MailKitMessage.cs index 2cc2fa9..893836f 100644 --- a/Project/Send_MailKitMessage.cs +++ b/Project/Send_MailKitMessage.cs @@ -1,5 +1,6 @@ using MimeKit; using System; +using System.Collections; using System.IO; using System.Management.Automation; using System.Reflection; @@ -89,6 +90,20 @@ public class Send_MailKitMessage : PSCmdlet Mandatory = false)] public string[] AttachmentList { get; set; } + [Parameter( + Mandatory = false)] + [ValidateSet(new string[] + { + "Normal", + "High", + "Low" + })] + public string Priority { get; set; } = "Normal"; + + [Parameter( + Mandatory = false)] + public Hashtable InlineImages { get; set; } + // This method gets called once for each cmdlet in the pipeline when the pipeline starts executing protected override void BeginProcessing() { @@ -151,9 +166,58 @@ protected override void ProcessRecord() } } + //inline attachment(s) + if(InlineImages != null && InlineImages.Count > 0) + { + foreach(object obj in InlineImages) + { + DictionaryEntry dictionaryEntry = (dictionaryEntry)obj; + string contentId = dictionaryEntry.Key.ToString(); + string text = dictionaryEntry.Value.ToString(); + if(File.Exists(text)) + { + string[] array = MimeTypes.GetMimeType(text).Split(new char[] + { + '/' + }); + MimePart attachment = new MimePart(new ContentType(array[0], array[1])) + { + Content = new MimeContent(File.OpenRead(text), ContentEncoding.Default), + ContentDisposition = new ContentDisposition("inline"), + ContentTransferEncoding = ContentEncoding.Base64, + ContentId = contentId, + FileName = Path.GetFileName(text) + }; + Body.LinkedResources.Add(attachment); + } + else + { + base.WriteWarning("Inline image file not found: " + text); + } + } + } + //add bodybuilder to body Message.Body = Body.ToMessageBody(); + //set message priority + string prio = Priority.ToLower(); + if(!(prio == "high")) + { + if(prio == "low") + { + Message.Headers.Add("X-Priority", "5 (Lowest)"); + Message.Headers.Add("X-MSMail-Priority", "Low"); + Message.Headers.Add("Importance", "Low"); + } + } + else + { + Message.Headers.Add("X-Priority", "1 (Highest)"); + Message.Headers.Add("X-MSMail-Priority", "High"); + Message.Headers.Add("Importance", "High"); + } + //smtp send Client.Connect(SMTPServer, Port, (UseSecureConnectionIfAvailable.IsPresent ? MailKit.Security.SecureSocketOptions.Auto : MailKit.Security.SecureSocketOptions.None)); if (Credential != null)