예제 #1
0
        private void SendEmployeeLeaveApprovalNotificationList(string attachmentPath)
        {
            try
            {
                List <EmailAlert> emailAlertList = EmailAlert.GetEmployeeLeaveApprovalNotificationList(Convert.ToInt32(DropDownListFinancialPeriod.SelectedValue), Convert.ToDateTime(TextBoxStartDate.Text), Convert.ToDateTime(TextBoxEndDate.Text), this.employeeId, DropDownListLeaveType.SelectedItem.Text);

                Attachment attachment = null;
                if (attachmentPath.Length > 0)
                {
                    attachment = new Attachment(attachmentPath);
                }

                foreach (EmailAlert emailAlert in emailAlertList)
                {
                    MailMessage mailMessage = new MailMessage(ConfigurationManager.AppSettings["administrationEmailAddress"].ToString(), emailAlert.EmailAddress /*"*****@*****.**"*/);

                    mailMessage.Subject    = emailAlert.EmailSubject;
                    mailMessage.Body       = emailAlert.EmailBody;
                    mailMessage.IsBodyHtml = true;

                    if (attachmentPath.Length > 0)
                    {
                        mailMessage.Attachments.Add(attachment);
                    }

                    SmtpClient smtpClient = new SmtpClient(ConfigurationManager.AppSettings["mailRelay"].ToString());
                    smtpClient.Port        = Convert.ToInt32(ConfigurationManager.AppSettings["port"]);
                    smtpClient.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["administrationEmailAddress"].ToString(), ConfigurationManager.AppSettings["password"].ToString());
                    smtpClient.EnableSsl   = true;
                    smtpClient.Send(mailMessage);
                }
            }
            catch (Exception ex)
            {
                LabelError.Text    = "";
                LabelError.Text   += ex.Message /* + " - " + ex.InnerException.ToString()*/;
                PanelError.Visible = true;
            }
        }