public MimeHelper(System.IO.Stream inputStream) { using (System.IO.StreamReader sr = new System.IO.StreamReader(inputStream, true)) { string streamContents = sr.ReadToEnd(); Chilkat.MailMan mailMan = new Chilkat(); mailMan.UnlockComponent(@"WRKSHRMAILQ_cFSLZe4MnB2y"); m_email = new Chilkat.Email(); if (!m_email.SetFromMimeText(streamContents)) throw new ArgumentException(); } }
public async Task <ActionResult <Models.APICallResult> > sendDirectiveEMailMessage(int motionId) { SqlConnection objSqlConnection1 = null; SqlConnection objSqlConnection2 = null; SqlCommand objSqlCommandGetMotionRecipients; SqlCommand objSqlCommandUpdateMotionRecipient; SqlDataReader objSqlDataGetMotionRecipients; System.Text.StringBuilder sbCommandText; Chilkat.Mht objChilkatMht; Chilkat.Email objChilkatEmail; Chilkat.MailMan objChilkatMailMan; HashSet <int> hsSentMotionRecipient; Models.APICallResult apiCallResult = new Models.APICallResult(); try { objSqlConnection1 = new SqlConnection(this._configuration["ConnectionStrings:MotionManager"]); await objSqlConnection1.OpenAsync(); objSqlConnection2 = new SqlConnection(this._configuration["ConnectionStrings:MotionManager"]); await objSqlConnection2.OpenAsync(); sbCommandText = new System.Text.StringBuilder(); sbCommandText.Append("UPDATE MotionRecipient "); sbCommandText.Append(" SET NotificationSent = 1 "); sbCommandText.Append(" WHERE MotionRecipientID = @MotionID "); objSqlCommandUpdateMotionRecipient = objSqlConnection1.CreateCommand(); objSqlCommandUpdateMotionRecipient.CommandText = sbCommandText.ToString(); objSqlCommandUpdateMotionRecipient.Parameters.Add(new SqlParameter("@MotionID", System.Data.SqlDbType.Int)); objSqlCommandUpdateMotionRecipient.CommandTimeout = 600; objSqlCommandUpdateMotionRecipient.Prepare(); sbCommandText = new System.Text.StringBuilder(); sbCommandText.Append("SELECT MR.MotionRecipientID, TR.TargetName, TR.ContactEMailAddress "); sbCommandText.Append(" FROM MotionRecipient MR INNER JOIN TargetRecipient TR ON MR.TargetRecipientID = TR.TargetRecipientID "); sbCommandText.Append(" WHERE MR.MotionID = @MotionID "); objSqlCommandGetMotionRecipients = objSqlConnection2.CreateCommand(); objSqlCommandGetMotionRecipients.CommandText = sbCommandText.ToString(); objSqlCommandGetMotionRecipients.Parameters.Add(new SqlParameter("@MotionID", System.Data.SqlDbType.Int)); objSqlCommandGetMotionRecipients.CommandTimeout = 600; objSqlCommandGetMotionRecipients.Parameters[0].Value = motionId; objSqlDataGetMotionRecipients = objSqlCommandGetMotionRecipients.ExecuteReader(); if (objSqlDataGetMotionRecipients.HasRows) { objChilkatMht = new Chilkat.Mht(); objChilkatMailMan = new Chilkat.MailMan(); objChilkatMht.UnlockComponent(ApplicationValues.TCH_CHILKAT_UNLOCK_CODE); objChilkatMailMan.UnlockComponent(ApplicationValues.TCH_CHILKAT_UNLOCK_CODE); objChilkatMailMan.SmtpHost = this._configuration["AppSettings:SMTPHostName"]; objChilkatMailMan.SmtpPort = int.Parse(this._configuration["AppSettings:SMTPPort"]); if (this._configuration["AppSettings:SMTPAuthenticate"] == "true") { objChilkatMailMan.SmtpUsername = this._configuration["AppSettings:SMTPUserName"]; objChilkatMailMan.SmtpPassword = this._configuration["AppSettings:SMTPPassword"]; } objChilkatMailMan.SmtpSsl = (this._configuration["AppSettings:SMTPUseSSL"] == "true"); objChilkatMailMan.StartTLS = (this._configuration["AppSettings:SMTPIssueStartTLS"] == "true"); if (!string.IsNullOrEmpty(this._configuration["AppSettings:SMTPLogonDomain"])) { objChilkatMailMan.SmtpLoginDomain = this._configuration["AppSettings:SMTPLogonDomain"]; } string strBaseUrl = string.Format("{0}://{1}{2}", Request.Scheme, Request.Host, Request.PathBase); string strUrl = string.Format("{0}/{1}/{2}/", strBaseUrl, "render/directiveEMailMessage", motionId); objChilkatEmail = new Chilkat.Email(); objChilkatEmail.SetFromMimeText(objChilkatMht.GetEML(strUrl)); hsSentMotionRecipient = new HashSet <int>(); while (await objSqlDataGetMotionRecipients.ReadAsync()) { objChilkatEmail.AddTo(objSqlDataGetMotionRecipients.GetString(1), objSqlDataGetMotionRecipients.GetString(2)); hsSentMotionRecipient.Add(objSqlDataGetMotionRecipients.GetInt32(0)); } // while (await objSqlDataGetMotionRecipients.ReadAsync()) objChilkatEmail.From = this._configuration["AppSettings:DirectiveEMailFromAccount"]; objChilkatEmail.Subject = this._configuration["AppSettings:DirectiveEMailSubjectText"]; //Chilkat.Task objChilkatTask = objChilkatMailMan.SendEmailAsync(objChilkatEmail); //if (objChilkatTask.LastMethodSuccess) if (objChilkatMailMan.SendEmail(objChilkatEmail)) { foreach (int intMotionRecipientID in hsSentMotionRecipient) { objSqlCommandUpdateMotionRecipient.Parameters[0].Value = intMotionRecipientID; await objSqlCommandUpdateMotionRecipient.ExecuteNonQueryAsync(); } } else { // PROGRAMMER's NOTE: need to log error return(StatusCode(StatusCodes.Status500InternalServerError, objChilkatMailMan.LastErrorText)); }; } objSqlDataGetMotionRecipients.Close(); apiCallResult.resultCode = APICallResult.RESULT_CODE_SUCCESS; return(Ok(apiCallResult)); } catch (Exception ex1) { return(StatusCode(StatusCodes.Status500InternalServerError, ex1.Message)); } finally { if (objSqlConnection1.State == System.Data.ConnectionState.Open) { objSqlConnection1.Close(); } if (objSqlConnection2.State == System.Data.ConnectionState.Open) { objSqlConnection2.Close(); } } } // sendDirectiveEMailMessage()
// TODO: ProtectProcess - fix test, bring back mime //[Test] public void TestModifyMime() { IUniversalRequestObject uro = UroFromMimeBytes("TestPlainTextMessageBody"); // Lets change some properties on the mime string mimeContent = uro.OriginalContentBytes.Data.AsString(uro.OriginalContentBytes.Data.Length, Encoding.Unicode); // Lets get ride of the old mime uro.OriginalContentBytes.Data.Dispose(); // Now lets modify it. using (Chilkat.Email email = new Chilkat.Email()) { email.SetFromMimeText(mimeContent); email.Subject = "Processed: " + email.Subject; email.AddTo("blackhole2", "*****@*****.**"); email.AddCC("blackhole3", "*****@*****.**"); email.AddBcc("blackhole4", "*****@*****.**"); email.Body += " And don't forget it!"; email.AddFileAttachment(TEST_FILE_PATH + @"\test.ppt"); Assert.AreEqual(3, email.NumTo); Assert.AreEqual(2, email.NumCC); Assert.AreEqual(2, email.NumBcc); UnicodeEncoding encoding = new UnicodeEncoding(); string modifiedMime = MimeProxy.InsertBccRecipientsIntoMime(email); MemoryStream mimeStream = new MemoryStream(encoding.GetBytes(modifiedMime)); uro.OriginalContentBytes.Data = new Workshare.Policy.BinaryData(mimeStream); } // Lets synchronize the URO with the MIME. using (Stream str = uro.OriginalContentBytes.Data.AsStream()) { MimeProxy mimeProxy = new MimeProxy(str); Email2Uro email2Uro = new Email2Uro(mimeProxy); email2Uro.Convert(RequestChannel.Outlook, uro); } //sender Assert.IsTrue(1 == uro.Source.Items.Count, "Should only be a single source item"); Assert.AreEqual("*****@*****.**", uro.Source.Items[0].Content, "Mismatch in email emailAddress"); Assert.AreEqual("lnpair", uro.Source.Items[0].Properties[SMTPPropertyKeys.DisplayName], "Mismatch in email emailAddress"); //recips Assert.AreEqual(7, uro.Destination.Items.Count); Assert.AreEqual("*****@*****.**", uro.Destination.Items[0].Content, "Mismatch in email emailAddress"); Assert.AreEqual("Black Hole", uro.Destination.Items[0].Properties[SMTPItemPropertyKeys.DisplayName], "Mismatch in email emailAddress"); Assert.AreEqual(AddressType.To, uro.Destination.Items[0].Properties[SMTPItemPropertyKeys.AddressType], "Destination item 1 should be of AddressType: To"); Assert.AreEqual("*****@*****.**", uro.Destination.Items[1].Content, "Mismatch in email emailAddress"); Assert.AreEqual("Pair Adm", uro.Destination.Items[1].Properties[SMTPItemPropertyKeys.DisplayName], "Mismatch in email emailAddress"); Assert.AreEqual(AddressType.To, uro.Destination.Items[1].Properties[SMTPItemPropertyKeys.AddressType], "Destination item 2 should be of AddressType: To"); Assert.AreEqual("*****@*****.**", uro.Destination.Items[2].Content, "Mismatch in email emailAddress"); Assert.AreEqual("lnpair", uro.Destination.Items[2].Properties[SMTPItemPropertyKeys.DisplayName], "Mismatch in email emailAddress"); Assert.AreEqual(AddressType.CC, uro.Destination.Items[2].Properties[SMTPItemPropertyKeys.AddressType], "Destination item 3 should be of AddressType: Cc"); Assert.AreEqual("*****@*****.**", uro.Destination.Items[3].Content, "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", uro.Destination.Items[3].Properties[SMTPItemPropertyKeys.DisplayName], "Mismatch in email emailAddress"); Assert.AreEqual(AddressType.BCC, uro.Destination.Items[3].Properties[SMTPItemPropertyKeys.AddressType], "Destination item 3 should be of AddressType: Bcc"); // New recipients added. Assert.AreEqual("*****@*****.**", uro.Destination.Items[4].Content, "Mismatch in email emailAddress"); Assert.AreEqual("blackhole2", uro.Destination.Items[4].Properties[SMTPItemPropertyKeys.DisplayName], "Mismatch in email emailAddress"); Assert.AreEqual(AddressType.To, uro.Destination.Items[4].Properties[SMTPItemPropertyKeys.AddressType], "Destination item 3 should be of AddressType: Bcc"); Assert.AreEqual("*****@*****.**", uro.Destination.Items[5].Content, "Mismatch in email emailAddress"); Assert.AreEqual("blackhole3", uro.Destination.Items[5].Properties[SMTPItemPropertyKeys.DisplayName], "Mismatch in email emailAddress"); Assert.AreEqual(AddressType.CC, uro.Destination.Items[5].Properties[SMTPItemPropertyKeys.AddressType], "Destination item 3 should be of AddressType: Bcc"); Assert.AreEqual("*****@*****.**", uro.Destination.Items[6].Content, "Mismatch in email emailAddress"); Assert.AreEqual("blackhole4", uro.Destination.Items[6].Properties[SMTPItemPropertyKeys.DisplayName], "Mismatch in email emailAddress"); Assert.AreEqual(AddressType.BCC, uro.Destination.Items[6].Properties[SMTPItemPropertyKeys.AddressType], "Destination item 3 should be of AddressType: Bcc"); //attachments Assert.AreEqual(1, uro.Attachments.Count); Assert.AreEqual("test.ppt", uro.Attachments[0].Name, "Mismatch in attachment name"); Assert.AreEqual("application/vnd.ms-powerpoint; name=test.ppt", uro.Attachments[0].ContentType, "Mismatch in attachment content type"); Assert.IsTrue(0 < uro.Attachments[0].Data.Length, "Expected the attachments data length to be greater then zero"); using (Stream str = uro.Attachments[0].Data.AsStream()) { Assert.IsTrue(0 < str.Length, "Expected to find a non-empty stream"); } //properties Assert.AreEqual(8, uro.Properties.Count); Assert.AreEqual(String.Empty, uro.Properties[MailMessagePropertyKeys.FileHeader], "Mismatch in Property"); Assert.AreEqual("This body is plain text. And don't forget it!", uro.Properties[MailMessagePropertyKeys.Body], "Mismatch in Property"); Assert.AreEqual("This body is plain text. And don't forget it!", uro.Properties[MailMessagePropertyKeys.FormattedBody], "Mismatch in Property"); Assert.AreEqual("Processed: TestPlainTextMessageBody", uro.Properties[MailMessagePropertyKeys.Subject], "Mismatch in Property"); Assert.AreEqual("Outlook", uro.Properties[SMTPPropertyKeys.RequestChannel], "Mismatch in Property"); Assert.AreEqual("test.ppt ", uro.Properties[MailMessagePropertyKeys.Attachments], "Mismatch in Property"); Assert.AreEqual("3", uro.Properties[MailMessagePropertyKeys.xPriority], "Mismatch in Property"); uro.OriginalContentBytes.Data.Dispose(); foreach (RequestAttachment ra in uro.Attachments) { ra.Dispose(); } }
public void TestModifyMimeUsingChilkatDirectly() { byte[] mimebytes = File.ReadAllBytes(Path.Combine(m_testPath, "TestPlainTextMessageBody")); using (MimeProxy proxy = new MimeProxy(mimebytes)) { // Now lets modify it. using (Chilkat.Email email = new Chilkat.Email()) { email.SetFromMimeText(proxy.MimeContent); email.Subject = "Processed: " + email.Subject; email.AddTo("blackhole2", "*****@*****.**"); email.AddCC("blackhole3", "*****@*****.**"); email.AddBcc("blackhole4", "*****@*****.**"); email.Body += " And don't forget it!"; email.AddFileAttachment(Path.Combine(m_testPath, @"test.ppt")); Assert.AreEqual(3, email.NumTo); Assert.AreEqual(2, email.NumCC); Assert.AreEqual(2, email.NumBcc); proxy.MimeContent = MimeProxy.InsertBccRecipientsIntoMime(email); } Assert.AreEqual("*****@*****.**", proxy.Sender.EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("lnpair", proxy.Sender.Name, "Mismatch in email emailAddress"); Assert.AreEqual(3, proxy.ToRecipients.Count); Assert.AreEqual(2, proxy.CcRecipients.Count); Assert.AreEqual(2, proxy.BccRecipients.Count); Assert.AreEqual("*****@*****.**", proxy.ToRecipients[0].EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("Black Hole", proxy.ToRecipients[0].Name, "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", proxy.ToRecipients[1].EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("Pair Adm", proxy.ToRecipients[1].Name, "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", proxy.ToRecipients[2].EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("blackhole2", proxy.ToRecipients[2].Name, "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", proxy.CcRecipients[0].EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("lnpair", proxy.CcRecipients[0].Name, "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", proxy.CcRecipients[1].EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("blackhole3", proxy.CcRecipients[1].Name, "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", proxy.BccRecipients[0].EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", proxy.BccRecipients[0].Name, "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", proxy.BccRecipients[1].EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("blackhole4", proxy.BccRecipients[1].Name, "Mismatch in email emailAddress"); Assert.AreEqual(1, proxy.Attachments.Count); Assert.AreEqual("test.ppt", proxy.Attachments[0].DisplayName, "Mismatch in attachment name"); Assert.AreEqual("application/vnd.ms-powerpoint; name=test.ppt", proxy.Attachments[0].ContentType, "Mismatch in attachment content type"); Assert.IsTrue(proxy.Attachments[0].FileName.Contains("test.ppt"), "Expected to find a non-empty stream"); Assert.AreEqual("This body is plain text. And don't forget it!", proxy.FormattedBodyText, "Mismatch in Property"); Assert.AreEqual("Processed: TestPlainTextMessageBody", proxy.Subject, "Mismatch in Property"); } }