public string Update(int id, string name, string description)
        {
            string msg;

            try
            {
                Origin model = service.GetById(id);
                model.Name        = name;
                model.Description = description;
                model.ChangedBy   = User.Identity.GetUserId();
                service.Update(model);
                msg = "Saved Successfully";
            }
            catch (Exception ex)
            {
                msg = "Error occured:" + ex.Message;
            }
            return(msg);
        }
示例#2
0
        public IActionResult Info(Guid id)
        {
            var res = _origin.GetById(id);

            return(View(res));
        }
示例#3
0
        public IActionResult Listener(SendMailViewModel model)
        {
            try
            {
                /*
                 * var files = Request.Form.Files;
                 *
                 * if (files.Any(f => f.Length == 0))
                 * {
                 *  return BadRequest();
                 * }
                 */
                var origin = _origin.GetById(model.MailKey);

                var mail = new MimeMessage();

                mail.From.Add(new MailboxAddress(origin.MailAccount.Mail));

                foreach (var d in origin.Destinies)
                {
                    mail.To.Add(new MailboxAddress(d.Email));
                }

                var body = $"{origin.Body}\n\n";

                foreach (var p in model.Properties)
                {
                    body += $"{p.Key}: {p.Value} \n\n";
                }

                //mail.Body += $"<hr>";

                if (!string.IsNullOrEmpty(origin.Signature))
                {
                    body += $"\n\n{origin.Signature}";
                }

                mail.Body = new TextPart(MimeKit.Text.TextFormat.Text)
                {
                    Text = body
                };

                mail.Subject = origin.Subject;

                using (var client = new SmtpClient())
                {
                    try
                    {
                        if (origin.MailAccount.UseSSL)
                        {
                            client.Connect(origin.MailAccount.Server, origin.MailAccount.Port, origin.MailAccount.UseSSL);
                            client.Authenticate(origin.MailAccount.User, origin.MailAccount.Password);
                        }

                        else
                        {
                            client.Connect(origin.MailAccount.Server, origin.MailAccount.Port, SecureSocketOptions.None);
                        }

                        client.AuthenticationMechanisms.Remove("XOAUTH2");

                        client.Send(mail);
                    }
                    catch
                    {
                        //log an error message or throw an exception or both.
                        throw;
                    }
                    finally
                    {
                        client.Disconnect(true);
                        client.Dispose();
                    }
                }


                //var mailService = new SmtpClient(origin.MailAccount.Server, origin.MailAccount.Port);



                return(Ok());
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }