///// <summary> ///// Редактирование значения ///// </summary> ///// <param name="val">значение</param> ///// <returns>измененное знач.</returns> //private string fewerValue(double val) //{ // return Convert.ToString(val * Math.Pow(10F, 1 * vsRatio)); //} /// <summary> /// Создание. Подготовка. Отправка письма. /// </summary> /// <param name="tableSource">таблица с данными</param> /// <param name="dtSend">выбранный промежуток</param> /// <param name="to">получатель</param> public void SendMailToNSS(IEnumerable <HandlerDbTaskCalculate.PUT_PARAMETER> parameters , IEnumerable <TepCommon.HandlerDbTaskCalculate.VALUE> values , Func <int, int, float, int, float> fGetValueAsRatio , DateTime dtSend , string to) { string bodyMsg = string.Empty , sbjct = string.Empty; DateTime reportDate = DateTime.MinValue; reportDate = dtSend.AddHours(6).Date;//?? sbjct = @"Отчет о выработке электроэнергии НТЭЦ-5 за " + reportDate.ToShortDateString(); bodyMsg = createBodyToSend(parameters, values, fGetValueAsRatio, reportDate); if (sbjct.Equals(string.Empty) == false) { using (OutlookMessage outlookMessage = new OutlookMessage()) { if (outlookMessage.Format(sbjct, bodyMsg, to) == true) { outlookMessage.Send(); } else { ; } } } else { ; } }
static void SendOutlookMail(string strSubject, string message, string fullFileName, string txtEmail, string txtEmailcc) { outlook.MailItem OutlookMessage; outlook.Application AppOutlook = new outlook.Application(); LogWriter log = new LogWriter(); try { OutlookMessage = AppOutlook.CreateItem(outlook.OlItemType.olMailItem); outlook.Recipients Recipients = OutlookMessage.Recipients; //OutlookMessage.From = "*****@*****.**"; OutlookMessage.Subject = strSubject; OutlookMessage.Body = message; OutlookMessage.BodyFormat = outlook.OlBodyFormat.olFormatHTML; if (!string.IsNullOrWhiteSpace(fullFileName)) { OutlookMessage.Attachments.Add(fullFileName, outlook.OlAttachmentType.olByValue); } if (!string.IsNullOrWhiteSpace(txtEmail)) { string[] arrAddTos = txtEmail.Split(new char[] { ';', ',' }); foreach (string strAddr in arrAddTos) { if (!string.IsNullOrWhiteSpace(strAddr) && strAddr.IndexOf('@') != -1) { Recipients.Add(strAddr.Trim()); } else { if ((Utilities.IsBitSet(Program.iLoc, 0)) || (Utilities.IsBitSet(Program.iLoc, 1))) // Toronto or Montreal { log.LogWrite(Program.torbackupPath, Program.txtOutputFile, Environment.UserName + "," + DateTime.Now + "," + fullFileName + "," + "Bad to-address: " + strAddr); } if ((Utilities.IsBitSet(Program.iLoc, 2)) || (Utilities.IsBitSet(Program.iLoc, 3))) // Vancouver or Calgary { log.LogWrite(Program.vanbackupPath, Program.txtOutputFile, Environment.UserName + "," + DateTime.Now + "," + fullFileName + "," + "Bad to-address: " + strAddr); } // throw new Exception("Bad to-address: " + txtEmail); } } } else { if ((Utilities.IsBitSet(Program.iLoc, 0)) || (Utilities.IsBitSet(Program.iLoc, 1))) // Toronto or Montreal { log.LogWrite(Program.torbackupPath, Program.txtOutputFile, Environment.UserName + "," + DateTime.Now + "," + fullFileName + "," + "Must specify to-address."); } if ((Utilities.IsBitSet(Program.iLoc, 2)) || (Utilities.IsBitSet(Program.iLoc, 3))) // Vancouver or Calgary { log.LogWrite(Program.vanbackupPath, Program.txtOutputFile, Environment.UserName + "," + DateTime.Now + "," + fullFileName + "," + "Must specify to-address."); } } //throw new Exception("Must specify to-address"); //Parse 'sCc' if (!string.IsNullOrWhiteSpace(txtEmailcc)) { string[] arrAddTos = txtEmailcc.Split(new char[] { ';', ',' }); foreach (string strAddr in arrAddTos) { if (!string.IsNullOrWhiteSpace(strAddr) && strAddr.IndexOf('@') != -1) { Recipients.Add(strAddr.Trim()); } else { if ((Utilities.IsBitSet(Program.iLoc, 0)) || (Utilities.IsBitSet(Program.iLoc, 1))) // Toronto or Montreal { log.LogWrite(Program.torbackupPath, Program.txtOutputFile, Environment.UserName + "," + DateTime.Now + "," + fullFileName + "," + "Bad cc-address: " + strAddr); } if ((Utilities.IsBitSet(Program.iLoc, 2)) || (Utilities.IsBitSet(Program.iLoc, 3))) // Vancouver or Calgary { log.LogWrite(Program.vanbackupPath, Program.txtOutputFile, Environment.UserName + "," + DateTime.Now + "," + fullFileName + "," + "Bad cc-address: " + strAddr); } } //throw new Exception("Bad CC-address: " + txtEmailcc); } } else { if ((Utilities.IsBitSet(Program.iLoc, 0)) || (Utilities.IsBitSet(Program.iLoc, 1))) // Toronto or Montreal { log.LogWrite(Program.torbackupPath, Program.txtOutputFile, Environment.UserName + "," + DateTime.Now + "," + fullFileName + "," + "Must specify cc-address."); } if ((Utilities.IsBitSet(Program.iLoc, 2)) || (Utilities.IsBitSet(Program.iLoc, 3))) // Vancouver or Calgary { log.LogWrite(Program.vanbackupPath, Program.txtOutputFile, Environment.UserName + "," + DateTime.Now + "," + fullFileName + "," + "Must specify cc-address."); } } //throw new Exception("Must specify to-address"); OutlookMessage.Send(); } catch (Exception ex) { } // MessageBox.Show("Mail could not be sent") 'if you dont want this message, simply delete this line finally { OutlookMessage = null /* TODO Change to default(_) if this is not a reference type */; AppOutlook = null /* TODO Change to default(_) if this is not a reference type */; } return; }