Ejemplo n.º 1
0
 public void Write(Recepients recipient)
 {
     if (_db.Recepients.Contains(recipient))
     {
         return;
     }
     _db.Recepients.InsertOnSubmit(recipient);
 }
Ejemplo n.º 2
0
 public int Create(Recepients recepients)
 {
     if (recepients.Id != 0)
     {
         return(recepients.Id);
     }
     _db.Recepients.InsertOnSubmit(recepients);
     return(recepients.Id);
 }
Ejemplo n.º 3
0
        private void retrieveDataFromExcel()
        {
            try{
                Excel.Worksheet xlWorksheet = (Excel.Worksheet)workbook.Sheets[1];
                Excel.Range     xlRange     = xlWorksheet.UsedRange;
                int             rowCount    = xlRange.Rows.Count;
                int             columnCount = xlRange.Columns.Count;
                //  String emailHeader =null, empIDHeader =null;
                for (int i = 1; i < rowCount + 1; i++)
                {
                    SortedList fieldMap = new SortedList();
                    for (int j = 1; j < columnCount + 1; j++)
                    {
                        object      rangeObject = xlWorksheet.Cells[i, j];
                        Excel.Range range       = (Excel.Range)rangeObject;
                        Object      rangeValue  = range.Value2;

                        String cellValue;
                        try
                        {
                            cellValue = rangeValue.ToString();
                        }catch (NullReferenceException)
                        {
                            cellValue = String.Empty;
                        }
                        if (i == 1)
                        {
                            Headers.Add(cellValue);
                        }
                        else
                        {
                            fieldMap.Add(Headers[j - 1], cellValue);
                        }
                    }
                    if (i != 1)
                    {
                        Recepients.Add(new Recepient(fieldMap));
                    }
                }
            }catch (Exception ex) {
                MessageBox.Show(ex.Message, "Error while reading Excel file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ErrorFree = false;
            }
            finally{
                workbook.Close();
            }
        }
Ejemplo n.º 4
0
        SendMail([FromBody] Recepients recipients)     //passing the recipient object having recipients and groups strings.
        {
            SmtpClient client = new SmtpClient();

            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.EnableSsl      = false;
            client.Host           = "smtprr.cerner.com";
            client.Port           = 25;

            // setup Smtp authentication automatically
            client.UseDefaultCredentials = true;

            string[] Recipients       = recipients.recepientString.Split(',');
            string[] Groups           = recipients.requestedGroups.Split(',');
            bool[]   visited_location = new bool[Groups.Length]; // create an array for keeping track of visiting some other array

            for (int i = 0; i < Groups.Length; ++i)
            {
                visited_location[i] = false; // set all to false to begin
            }

            //below code will map all groups to their respective admins and send a
            //single mail containing details of all the requested groups.
            try
            {
                for (int i = 0; i < Recipients.Length; i++)
                {
                    int    flag = 0;
                    string Body = "New Associate has requested to join groups:"; //body for our mail.
                    for (int j = 0; j < Recipients.Length; j++)
                    {
                        if (Recipients[j] == Recipients[i] && visited_location[j] != true)
                        {
                            visited_location[j] = true;
                            Body = Body + "\n" + Groups[j]; //adding requested groups to the body.
                            flag = 1;
                        }
                    }


                    if (flag == 1)
                    {
                        var         rec = new MailAddress(Recipients[i]);
                        MailMessage msg = new MailMessage("*****@*****.**", Recipients[i],
                                                          "New Group join Request from Associate.", Body); //creating a mail object.
                        msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                        msg.Headers.Add("Disposition-Notification-To", "*****@*****.**");
                        try
                        {
                            _logger.LogError($"Email sent to: {Recipients[i]}");
                            client.Send(msg);                    //sending the mail.
                        }
                        catch (SmtpFailedRecipientsException ex) //catching exceptions while sending mail.
                        {
                            for (int k = 0; k < ex.InnerExceptions.Length; k++)
                            {
                                SmtpStatusCode status = ex.InnerExceptions[k].StatusCode;
                                if (status == SmtpStatusCode.MailboxBusy ||
                                    status == SmtpStatusCode.MailboxUnavailable)
                                {
                                    Debug.WriteLine("Delivery failed - retrying in 5 seconds.");
                                    System.Threading.Thread.Sleep(5000);
                                    _logger.LogError($"Email sent to: {Recipients[i]}");
                                    client.Send(msg);
                                }
                                else
                                {
                                    Debug.WriteLine("Failed to deliver message to {0}",
                                                    ex.InnerExceptions[k].FailedRecipient);
                                    _logger.LogError($"Email could not be sent to: {Recipients[i]}");
                                }
                            }
                        }
                    }
                }

                return(Ok(recipients));
            }

            catch (Exception ex)
            {
                _logger.LogError($"Email could not be sent.");
                Debug.WriteLine("Exception caught in RetryIfBusy(): {0}", ex.ToString());
                return(StatusCode(500, "Internal server error"));
            }
        }
Ejemplo n.º 5
0
 public int Add(Recepients recipient)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 6
0
 /// <inheritdoc/>
 public bool IsValid(ISmsServiceConfig smsServiceConfig)
 {
     return((Recepients?.Any() ?? false) && (Recepients?.All(x => !string.IsNullOrWhiteSpace(x)) ?? false) && (smsServiceConfig?.CharacterLimit.HasValue ?? false ? Message.Length <= smsServiceConfig?.CharacterLimit : true));
 }
Ejemplo n.º 7
0
        /// <summary>
        ///     Добавление получателя.
        /// </summary>
        /// <param name="address"> Email получателя. </param>
        /// <returns> Сообщение. </returns>
        public EmailMessage AddRecepient(string address)
        {
            Recepients.Add(address);

            return(this);
        }