Esempio n. 1
0
        public async Task ProcessToSendMail(TicketScheduleModal ticketschedulemodal)
        {
            try
            {
                exceptions.FileText("Step BAL 14 Start");
                await Task.Run(() => SendEmail(ticketschedulemodal));

                exceptions.FileText("Step BAL 14 End");
            }
            catch (Exception ex)
            {
                exceptions.SendErrorToText(ex);
            }
        }
Esempio n. 2
0
        public void SendEmail(TicketScheduleModal ticketschedulemodal, string[] cc = null, string[] bcc = null, int tenantId = 0)
        {
            try
            {
                exceptions.FileText("Step BAL 15 Start");

                SMTPDetails smtpDetails    = ticketschedulemodal.SMTPDetails;
                string      emailToAddress = ticketschedulemodal.SendToEmailID;
                string      CCToAddress    = ticketschedulemodal.CreatedByEmailId;
                string      subject        = ticketschedulemodal.Emailsubject;
                string      body           = ticketschedulemodal.Emailbody;
                string      Attachmentfile = ticketschedulemodal.SearchOutputFileName;

                cc = new string[] { CCToAddress };

                string[] emailToList = emailToAddress.Split(',');

                if (emailToList.Length > 0)
                {
                    SmtpClient smtpClient = new SmtpClient(smtpDetails.SMTPServer, Convert.ToInt32(smtpDetails.SMTPPort));
                    smtpClient.EnableSsl             = smtpDetails.EnableSsl;
                    smtpClient.DeliveryMethod        = SmtpDeliveryMethod.Network;
                    smtpClient.UseDefaultCredentials = true;
                    smtpClient.Credentials           = new NetworkCredential(smtpDetails.FromEmailId, smtpDetails.Password);
                    {
                        using (MailMessage message = new MailMessage())
                        {
                            message.From = new MailAddress(smtpDetails.FromEmailId, smtpDetails.EmailSenderName);

                            if (cc != null)
                            {
                                if (cc.Length > 0)
                                {
                                    for (int i = 0; i < cc.Length; i++)
                                    {
                                        message.CC.Add(cc[i]);
                                    }
                                }
                            }
                            if (bcc != null)
                            {
                                if (bcc.Length > 0)
                                {
                                    for (int k = 0; k < bcc.Length; k++)
                                    {
                                        message.CC.Add(bcc[k]);
                                    }
                                }
                            }
                            message.Subject    = subject == null ? "" : subject;
                            message.Body       = body == null ? "" : body;
                            message.IsBodyHtml = smtpDetails.IsBodyHtml;
                            message.Attachments.Add(new Attachment(Attachmentfile));

                            if (emailToList.Length > 0)
                            {
                                foreach (string emailid in emailToList)
                                {
                                    message.To.Add(emailid);
                                }
                                smtpClient.Send(message);
                            }
                            else
                            {
                                getdata.SchedulerMailResult(ticketschedulemodal, false, "TS", "No Email ID Present to send", "SendEmail", "");
                            }

                            //message.To.Add(emailToAddress);
                        }
                    }
                }
                else
                {
                    getdata.SchedulerMailResult(ticketschedulemodal, false, "TS", "No Email ID Present to send", "SendEmail", "");
                }


                exceptions.FileText("Step BAL 15 End");
            }
            catch (SmtpFailedRecipientsException ex)
            {
                getdata.SchedulerMailResult(ticketschedulemodal, false, "TS", ex.InnerExceptions.ToString(), ex.Message.ToString(), ex.StackTrace.ToString(), ex.StatusCode.ToString());
            }
            catch (Exception ex)
            {
                getdata.SchedulerMailResult(ticketschedulemodal, false, "TS", ex.InnerException.ToString(), ex.Message.ToString(), ex.StackTrace.ToString(), "NoStatusCode");
                exceptions.SendErrorToText(ex);
            }
        }