Example #1
0
 public ChatHttpService(DuplexChannelBuilder<IRemoteService> channelBuilder, Administrator currentAdministrator)
     : base(channelBuilder, currentAdministrator)
 {
 }
Example #2
0
        protected string SendEmailToAdministrator(int employeeId, Administrator administrator, string employee)
        {
            string response;

            try
            {
                var fromAddress = GetAttribute("SMTPEmail");
                var toAddress = administrator.Email;
                string fromPassword = GetAttribute("SMTPPassword");
                string subject = GetAttribute("SMTPSubject");
                //string body = "Hello" + port + "\n";
                string body = employee;

                int port;
                int.TryParse(GetAttribute("SMTPPort"), out port);

                Console.WriteLine("fromAddress [" + fromAddress + "]");
                Console.WriteLine("toAddress [" + toAddress + "]");
                Console.WriteLine("fromPassword [" + fromPassword + "]");
                Console.WriteLine("subject [" + subject + "]");
                Console.WriteLine("body [" + body + "]");
                Console.WriteLine("emailAddress.SmtpHost [" + GetAttribute("SMTPHost") + "]");
                Console.WriteLine("emailAddress.SmtpPort [" + port + "]");

                Console.WriteLine(toAddress + " " + subject + " " + port);

                var smtp = new SmtpClient();
                {
                    smtp.Host = GetAttribute("SMTPHost");

                    smtp.Port = port;
                    smtp.EnableSsl = true;
                    smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
                }

                var photos = _db.Photos.Where(x => x.EmployeeId == employeeId).ToList();
                var message = new MailMessage(fromAddress, toAddress);

                foreach (var photo in photos)
                {
                    var stream = new MemoryStream(photo.Image);
                    var attachment = new Attachment(stream, photo.FileName.Trim());
                    message.Attachments.Add(attachment);
                }

                message.Subject = subject;
                message.Body = body;
                smtp.Send(message);
                Console.WriteLine("Email Success " + toAddress + " " + port);
                response = administrator.AdministratorId + " Success";
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                response = administrator.AdministratorId + " Failure";
            }

            return response;
        }