Example #1
0
        public async Task <ActionResult> Send(int id)
        {
            var userId      = User.Identity.GetUserId();
            var email       = _emailRepository.GetEmail(userId, id);
            var currentUser = _applicationUserRepository.GetApplicationUser(userId);

            var emailSender = new EmailSender.Email(new EmailParams
            {
                HostSmtp            = currentUser.HostSmtp,
                Port                = currentUser.Port,
                EnableSsl           = currentUser.EnableSsl,
                SenderName          = currentUser.SenderName,
                SenderEmail         = currentUser.SenderEmail,
                SenderEmailPassword = currentUser.SenderEmailPassword
            });

            // Listę odbiorców maila konwertuję to listy adresów
            var listOfEmailRecipients = new List <string>();

            foreach (var emailRecipient in email.EmailRecipients)
            {
                listOfEmailRecipients.Add(emailRecipient.Address.Email);
            }


            await emailSender.Send(email.Subject, email.Message, listOfEmailRecipients);

            _emailRepository.UpdateSentDate(email, userId);

            return(Json(new
            {
                Success = true,
                Message = "Mail został wysłany"
            }));
        }
        public EmailModel GetEmail(int emailId)
        {
            EmailModel emailItem = repo.GetEmail(emailId);


            if (emailItem == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            return(emailItem);
        }
Example #3
0
        public ActionResult Email(int id = 0)
        {
            var userId = User.Identity.GetUserId();

            var email = id == 0 ?
                        _emailRepository.GetNewEmail(userId) :
                        _emailRepository.GetEmail(userId, id);


            var editEmail = PrepareEmailVm(email, userId);

            return(View(editEmail));
        }
Example #4
0
        public async Task <IActionResult> GetEmail(int contactId, int emailId)
        {
            var email = await _repo.GetEmail(contactId, emailId);

            return(Ok(email));
        }