Esempio n. 1
0
 public static void Email()
 {
     if (AllIssues != "")
     {
         var errEmail = new EmailObject()
         {
             Body = "Here Are the issues:" + AllIssues,
             To = "*****@*****.**",
             Subject = "Errors Caught"
         };
         var send = new GenerateEmail(errEmail);
     }
 }
Esempio n. 2
0
 private void sendEmail(EmailObject eml, bool errEmail = false)
 {
     string myDate = DateTime.Today.ToString("MMMM dd, yyyy");
     Outlook._Application _app = new Outlook.Application();
     Outlook._NameSpace _ns = _app.GetNamespace("MAPI");
     System.Threading.Thread.Sleep(5000); //wait for app to start
     Outlook.MailItem _mail = (Outlook.MailItem)_app.CreateItem(Outlook.OlItemType.olMailItem);
     try
     {
         int fileCount = 0;
         if (qryNames != null)
         {
             foreach (var qryName in qryNames)
             {
                 if (System.IO.File.Exists(AttachmentLocation + qryName))
                 {
                     _mail.Attachments.Add(AttachmentLocation + qryName);
                     fileCount++;
                 }
             }
         }
         _mail.Subject = myDate + " " + eml.Subject;
         _mail.To = eml.To;
         _mail.CC = eml.CC;
         _mail.Body = eml.Body;
         _mail.Importance = Outlook.OlImportance.olImportanceNormal;
         System.Threading.Thread.Sleep(5000); //wait for application to catch up with mail object
         ((Outlook.MailItem)_mail).Send();
         _ns.SendAndReceive(true); //send and receive
         _mail.Close(Outlook.OlInspectorClose.olDiscard);
         System.Threading.Thread.Sleep(5000); //wait for application to catch up with mail object
         _app.Quit();
         isSuccessful = true;
     }
     catch (COMException cEx)
     {
         if (cEx.Message != "The item has been moved or deleted.")
         {
             ErrorHandler.Handle(cEx);
             isSuccessful = false;
         }
     }
     catch (Exception x)
     {
         ErrorHandler.Handle(x);
         isSuccessful = false;
     }
 }
Esempio n. 3
0
 public GenerateEmail(EmailObject EmlObj, List<string> QryNames, string DownloadDestination)
 {
     qryNames = QryNames;
     AttachmentLocation = DownloadDestination;
     sendEmail(EmlObj);
 }
Esempio n. 4
0
 public GenerateEmail(EmailObject EmlObj)
 {
     sendEmail(EmlObj, true);
 }
Esempio n. 5
0
 private void Execute(bool ToBeEmailed)
 {
     //runs the process to execute queries and send results
     FormDataWrite();
     lblStatus.Text = "Executing....."; lblStatus.ForeColor = Color.DarkBlue; Update();
     ErrorHandler.AllIssues = "";
     var findSql = new FindSQL(this);
     var qryNames = findSql.QryNames;
     var sqlStrings = findSql.SqlStatements;
     var outputTypes = findSql.OutputTypes;
     //looping through all found queries
     for (int i = 0; i < qryNames.Count; i++)
     {
         string qryName = qryNames[i];
         string sqlString = sqlStrings[i];
         string outputType = outputTypes[i];
         var sqlData = new RunQuery(sqlString, qryName).sqlData;
         if (sqlData.Rows.Count > 0)
         {
             var push = new PushData(sqlData, txtFilePath.Text + qryName);
             switch (outputType)
             {
                 case "Excel":
                     push.WriteToExcel();
                     AppendToList(".xlsx");
                     break;
                 case "CSV":
                     push.WriteToCsv("|");
                     AppendToList(".csv");
                     break;
                 case "Command":
                     break;
                 default:
                     push.WriteToExcel();
                     AppendToList(".xlsx");
                     break;
             }
         }
         else if (sqlData.Rows.Count <= 0)
         {
             var ex = new Exception("The query resulted in no data");
             ErrorHandler.Handle(ex);
         }
     }
     if (ToBeEmailed) //if the email is needs to be emailed run the rest of the code
     {
         var EmlObj = new EmailObject() { To = txtTo.Text, Body = txtBody.Text, CC = txtCC.Text, Subject = txtSubject.Text };
         var GenerateEmail = new GenerateEmail(EmlObj, qryNames, txtFilePath.Text);
         if (ErrorHandler.AllIssues != "")
         {
             lblStatus.ForeColor = Color.Red; lblStatus.Text = "Sending Errors!";
             Update();
             var errMail = new EmailObject()  //create error email object;
             {
                 To = txtYourEmail.Text,
                 Subject = "SQL Sender Errors",
                 Body = ErrorHandler.AllIssues,
                 CC = txtCC.Text
             };
             var mail = new GenerateEmail(errMail);
         }
     }
     lblStatus.Text = "Ready";
     lblStatus.ForeColor = Color.Black;
     Update();
 }