/// <summary> /// Evaluates the internal expression. /// </summary> /// <param name="sourceText">The source text.</param> /// <param name="exportedFileDetails">The exported file details.</param> /// <returns></returns> public static string EvaluateInternalExpression(string sourceText, ExportedFileDetails exportedFileDetails) { PropertyInfo[] propertyInfos = typeof(ExportedFileDetails).GetProperties(); return(Keys.BodyKeysConcreteValue.Aggregate(sourceText, (current, keyValue) => current.Replace(keyValue.Key, propertyInfos.Where(key => key.Name == keyValue.Value).FirstOrDefault().GetValue(exportedFileDetails, null).ToString()))); }
public static bool SendEmail(ExportedFileDetails exportedFileDetails, VariableDispenser variableDispenser, Connections connections, IDTSComponentEvents componentEvents, string filePath, string from, string to, string subject, string body, string smtp) { bool retVal = false; bool refire = false; try { componentEvents.FireInformation(0, "SSISBulkExportTask", "Build the e-mail...", string.Empty, 0, ref refire); using (MailMessage mailMessage = new MailMessage { From = new MailAddress(EvaluateExpression(from, variableDispenser).ToString()), Subject = EvaluateExpression(subject, variableDispenser).ToString(), Body = EvaluateExpression(EvaluateInternalExpression(body, exportedFileDetails), variableDispenser).ToString(), }) { var strTo = EvaluateExpression(to, variableDispenser).ToString().Split(';'); foreach (string item in strTo) { mailMessage.To.Add(new MailAddress(item)); } try { componentEvents.FireInformation(0, "SSISBulkExportTask", string.Format("Send e-mail using {0}", GetConnectionParameter(connections[smtp].ConnectionString, "SmtpServer")), string.Empty, 0, ref refire); SmtpClient smtpClient = new SmtpClient(GetConnectionParameter(connections[smtp].ConnectionString, "SmtpServer")) { EnableSsl = Convert.ToBoolean(GetConnectionParameter(connections[smtp].ConnectionString, "EnableSsl")), UseDefaultCredentials = Convert.ToBoolean(GetConnectionParameter(connections[smtp].ConnectionString, "UseWindowsAuthentication")) }; componentEvents.FireInformation(0, "SSISBulkExportTask", "Send the e-mail", string.Empty, 0, ref refire); smtpClient.Send(mailMessage); componentEvents.FireInformation(0, "SSISBulkExportTask", "E-mail sended successfully", string.Empty, 0, ref refire); } catch (Exception exception) { componentEvents.FireError(0, "SSISBulkExportTask", string.Format("Problem: {0} {1}", exception.Message, exception.StackTrace), "", 0); retVal = false; } } retVal = true; } catch (Exception exception) { componentEvents.FireError(0, "SSISBulkExportTask", string.Format("Problem: {0} {1}", exception.Message, exception.StackTrace), "", 0); retVal = false; } return(retVal); }