Пример #1
0
        public void SendMailFromGmail(EmailInputModel input, string userEmail)
        {
            var userSubject = input.Subject;
            var userMessage = input.Message;

            var          fromAddress  = new MailAddress(Credential.Username, userEmail);
            var          toAddress    = new MailAddress(Credential.ReceiveAddress, "From funeral contact form");
            const string fromPassword = Credential.FuneralGmailPass;
            string       subject      = userSubject;

            var smtp = new SmtpClient
            {
                Host           = "smtp.gmail.com",
                Port           = 587,
                EnableSsl      = true,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                Credentials    = new NetworkCredential(fromAddress.Address, fromPassword),
                Timeout        = 20000,
            };

            using (var message = new MailMessage(fromAddress, toAddress)
            {
                Subject = subject,
                Body = userMessage,
            })
            {
                smtp.Send(message);
            }
        }
Пример #2
0
        public async Task <IActionResult> AttendeesAsync(int id, EmailInputModel input)
        {
            if (!ModelState.IsValid)
            {
                return(View("Compose", input));
            }

            var evnt = _eventService.GetEvent(id);

            if (evnt == null)
            {
                return(NotFound());
            }

            var authResult = await _authorizationService.AuthorizeAsync(User, evnt, Policy.CanEmail);

            if (!authResult.Succeeded)
            {
                return(Forbid());
            }

            var recipients = _eventService.GetAttendancesByEvent(id).Select(a => a.Attendee).ToList();
            var msg        = _emailSender.CreateMessage(User, recipients, input.Subject, input.Content);

            if (msg != null)
            {
                _ = _emailSender.SendAsync(msg);
            }

            _logger.LogInformation("{user} emailed to the attendees of event {event}", User.Identity.Name, id);

            return(Redirect(input.RedirectUrl));
        }
Пример #3
0
        public LogOnModel()
        {
            Title = "log_on_title";

            EmailInput    = new EmailInputModel("Email", "email", true);
            PasswordInput = new PasswordInputModel("Password", "password", true);
        }
        public void EmailInputModel(string name, string labelKey, bool isRequired)
        {
            var model = new EmailInputModel(name, labelKey, isRequired);

            Assert.AreEqual(name, model.Name);
            Assert.AreEqual(labelKey, model.LabelKey);
            Assert.AreEqual(isRequired, model.IsRequired);
        }
Пример #5
0
        public AdminInviteModel()
        {
            Title = "admin_invite_title";

            OrganizationUidInput = new HiddenInputModel("OrganizationUid");
            EmailInput           = new EmailInputModel("Email", "email", true);
            FirstNameInput       = new InputModel("FirstName", "first_name", true);
            LastNameInput        = new InputModel("LastName", "last_name", true);
        }
Пример #6
0
        public SignUpModel()
        {
            Title = "sign_up_title";

            EmailInput            = new EmailInputModel("Email", "email", true);
            FirstNameInput        = new InputModel("FirstName", "first_name", true);
            LastNameInput         = new InputModel("LastName", "last_name", true);
            OrganizationNameInput = new LongInputModel("OrganizationName", "organization_name", true);
            PasswordInput         = new PasswordInputModel("Password", "password", true);
            IsTermsAcceptedInput  = new CheckboxInputModel("IsTermsAccepted", "accept_terms", true);
        }
Пример #7
0
        public MvcHtmlString Email <TProperty>(Expression <Func <TModel, TProperty> > expression, string placeholder = null, string label = null)
        {
            ModelMetadata   modelMetadata   = ModelMetadata.FromLambdaExpression(expression, Helper.ViewData);
            EmailInputModel emailInputModel = new EmailInputModel(Helper,
                                                                  modelMetadata,
                                                                  ExpressionHelper.GetExpressionText(expression),
                                                                  label,
                                                                  placeholder);

            return(Helper.Partial("EditorTemplates/Forms/Input", emailInputModel));
        }
Пример #8
0
        private async Task LoadAsync(CinemaWorldUser user)
        {
            var email = await this.userManager.GetEmailAsync(user);

            this.Email = email;

            this.Input = new EmailInputModel
            {
                NewEmail = email,
            };

            this.IsEmailConfirmed = await this.userManager.IsEmailConfirmedAsync(user);
        }
Пример #9
0
        public async ValueTask <string> UpdateEmailRW(EmailInputModel emailModel)
        {
            if (string.IsNullOrWhiteSpace(emailModel.Email))
            {
                return("Enter the email");
            }
            string validationResult = await _validator.ValidateEmailInputModel(emailModel);

            if (!string.IsNullOrWhiteSpace(validationResult))
            {
                return(validationResult);
            }
            return("");
        }
Пример #10
0
        private async Task <EmailViewModel> BuildViewModel(EmailInputModel input = null)
        {
            var vm = new EmailViewModel
            {
                NewEmail        = input?.NewEmail,
                NewEmailConfirm = input?.NewEmailConfirm
            };

            var user = await _userManager.GetUserAsync(User);

            vm.Email            = user.Email;
            vm.IsEmailConfirmed = user.EmailConfirmed;

            return(vm);
        }
Пример #11
0
        public async ValueTask <ActionResult <string> > UpdateEmailByLeadId(EmailInputModel emailModel)
        {
            var message = await _wrapper.UpdateEmailRW(emailModel);

            if (string.IsNullOrWhiteSpace(message))
            {
                await _repo.UpdateEmailByLeadId(_mapper.Map <EmailDto>(emailModel));

                _logger.Info($"Update e-mail for lead with Id: {emailModel.LeadId} - {emailModel.Email} ");
                return(Ok("E-mail was updated"));
            }
            else
            {
                return(BadRequest(message));
            }
        }
Пример #12
0
        public async Task SendAsync(EmailInputModel emailInfo)
        {
            if (emailInfo == null)
            {
                throw new ArgumentNullException(nameof(emailInfo));
            }

            var storeNameMapped = MessageManager.toStoreName(emailInfo.StoreName);

            var emailAddressRecipient = MessageManager.EmailAddress(storeNameMapped);

            Debug.WriteLine($"Sending fake email to {emailAddressRecipient}");
            Debug.WriteLine($"Sending to {emailAddressRecipient} from {emailSettings.From}");

            await Task.FromResult(0);
        }
Пример #13
0
        public async Task SendAsync(EmailInputModel emailInfo)
        {
            if (emailInfo == null)
            {
                throw new ArgumentNullException(nameof(emailInfo));
            }

            var storeNameMapped = MessageManager.toStoreName(emailInfo.StoreName);

            var emailAddressRecipient = MessageManager.EmailAddress(storeNameMapped);

            var client = new SmtpClient()
            {
                Port                  = 587,
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                EnableSsl             = true,
                Timeout               = 5000,
                Host                  = "smtp.gmail.com",
                Credentials           = new NetworkCredential(emailSettings.Username, emailSettings.Password)
            };

            var subject = $"Oasis Application:TEST - {emailInfo.CustomerFirstName} {emailInfo.CustomerLastName}";
            var body    = emailInfo.CustomerInformation;
            //var message = new MailMessage(emailSettings.From, emailSettings.To, subject, body)
            var message = new MailMessage(emailSettings.From, emailAddressRecipient, subject, body)
            {
                BodyEncoding = UTF8Encoding.UTF8,
                DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
            };

            message.CC.Add(emailSettings.To);

            using (client)
            {
                try
                {
                    await client.SendMailAsync(message);
                }
                catch (SmtpException e)
                {
                    Debug.WriteLine(e.Message);
                    throw;
                }
            }
        }
Пример #14
0
        public async Task <IActionResult> SendFromGmail(EmailInputModel input)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction(nameof(ContactForm)));
            }

            var user = await this.userManager.GetUserAsync(this.User);

            var userEmail = await this.userManager.GetEmailAsync(user);

            gmailService.SendMailFromGmail(input, userEmail);

            ViewData["ErrorMessage"] = OtherConstants.EmailSendSuccessfully;
            TempData.Add("ErrorMessage", ViewData["ErrorMessage"]);

            return(RedirectToAction(nameof(SuccessSendedMail)));
        }
Пример #15
0
        public async Task <IActionResult> PostAsync([FromBody] EmailInputModel email)
        {
            //email.CustomerInformation = encrypter.Protect(email.CustomerInformation);
            Debug.WriteLine(email.CustomerInformation);
            try
            {
                await emailer.SendAsync(email);
            }
            catch (SmtpException e)
            {
                return(Ok("Received request but couldn't send emails"));
            }
            catch (Exception e)
            {
                return(Ok("Sorry, having trouble sending e-mail."));
            }

            return(Ok("Email successfully sent"));
        }
Пример #16
0
        public async ValueTask <string> ValidateEmailInputModel(EmailInputModel emailModel)
        {
            if ((!Regex.IsMatch(emailModel.Email, Validator.emailPattern)))
            {
                return("The Email is incorrect");
            }
            var leadId = _repo.GetById(emailModel.LeadId);

            if (leadId == null)
            {
                return("Lead was not found");
            }
            DataWrapper <int> dataWrapper = await _repo.CheckEmail(emailModel.Email);

            if (dataWrapper.Data != 0)
            {
                return("User with this email already exists");
            }
            return("");
        }
Пример #17
0
        public async Task <IActionResult> RewardeesAsync(int id, EmailInputModel input)
        {
            if (!ModelState.IsValid)
            {
                return(View("Compose", input));
            }

            var reward = _rewardService.GetReward(id);

            if (reward == null)
            {
                return(NotFound());
            }

            var authResult = await _authorizationService.AuthorizeAsync(User, reward, Policy.CanEmail);

            if (!authResult.Succeeded)
            {
                return(Forbid());
            }

            var recipients = _rewardService.GetRewardees(id).Where(r => r.RequirementsMet)
                             .Select(r => new User
            {
                Id        = r.Id,
                FirstName = r.FirstName,
                LastName  = r.LastName,
                Email     = r.Email
            }).ToList();
            var msg = _emailSender.CreateMessage(User, recipients, input.Subject, input.Content);

            if (msg != null)
            {
                _ = _emailSender.SendAsync(msg);
            }

            _logger.LogInformation("{user} emailed to the rewardees of reward {reward}", User.Identity.Name, id);

            return(Redirect(input.RedirectUrl));
        }
Пример #18
0
        public async Task <IActionResult> SendEmailAsync([FromBody] EmailInputModel contact)
        {
            await _emailService.SendEmail(contact.Name, contact.Phone, contact.Email, contact.Subject, contact.Message);

            return(Ok());
        }
Пример #19
0
        public async Task <IHttpActionResult> EmailInvoice(EmailInputModel model)
        {
            var fromAddress = ConfigurationManager.AppSettings["EmailFromAddress"];
            var user        = Request.GetOwinContext().Request.User;

            var order = await _repo.Get(model.OrderId);

            var report = new InvoiceReport(order) as SectionReport;

            report.Run();
            var memStream = new MemoryStream();
            var pdfExport = new PdfExport();

            pdfExport.Export(report.Document, memStream);
            memStream.Position = 0;
            var attachments = new Dictionary <string, MemoryStream> {
                { $"Invoice {order.Id.ToString("0000")}.pdf", memStream }
            };

            var mailMessage = new SendGridMessage {
                Subject             = model.Subject,
                From                = new MailAddress(fromAddress, user.Identity.Name),
                Text                = model.Body,
                Html                = model.Body.Replace("\n", "<br>"),
                StreamedAttachments = attachments
            };
            var to = model.Address.Where(a => !string.IsNullOrWhiteSpace(a)).ToList();

            if (to.Any())
            {
                mailMessage.AddTo(to);

                model.Bcc.ToList().ForEach(bcc => {
                    if (!string.IsNullOrWhiteSpace(bcc))
                    {
                        mailMessage.AddBcc(bcc);
                    }
                });
            }
            else
            {
                to = model.Bcc.Where(a => !string.IsNullOrWhiteSpace(a)).ToList();
                mailMessage.AddTo(to);
            }

            var delivery = await _repo.RecordInvoiceEmail(mailMessage, order.Id, user.Identity.Name);

            mailMessage.AddUniqueArgs(new Dictionary <string, string> {
                ["order_id"]    = order.Id.ToString(),
                ["delivery_id"] = delivery.Id.ToString()
            });

            try {
                var apiKey       = ConfigurationManager.AppSettings["SendGridApiKey"];
                var transportWeb = new Web(apiKey);
                await transportWeb.DeliverAsync(mailMessage);
            } catch (InvalidApiRequestException ex) {
                var       errorMessage = string.Join(", ", ex.Errors);
                Exception error        = ex;
                while (error != null)
                {
                    errorMessage += $",{error.Message}";
                    error         = error.InnerException;
                }
                await _repo.LogEmailDeliveryError(delivery.Id, errorMessage);

                throw;
            } catch (Exception ex) {
                var errorMessage = string.Empty;
                var error        = ex;
                while (error != null)
                {
                    errorMessage += $",{error.Message}";
                    error         = error.InnerException;
                }
                await _repo.LogEmailDeliveryError(delivery.Id, errorMessage);

                throw;
            }

            var email = string.Join(";", model.Address);

            if (!string.IsNullOrWhiteSpace(email))
            {
                order.Inquiry.Email = email;
            }
            if (order.InvoiceDate == null)
            {
                order.InvoiceDate = DateTime.Now;
            }
            var edited = await _repo.Edit(order, user.Identity.Name);

            return(Ok(edited));
        }
Пример #20
0
        public async Task <IActionResult> Index(EmailInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(await BuildViewModel(model)));
            }

            if (model.ResendEmailConfirmation)
            {
                var user = await _userManager.GetUserAsync(User);

                var userId = await _userManager.GetUserIdAsync(user);

                var email = await _userManager.GetEmailAsync(user);

                var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));

                var callbackUrl = Url.Action("Index", "ConfirmEmail", new
                {
                    area = "",
                    userId, code
                }, Request.Scheme);

                await _emailSender.SendEmailAsync(
                    new MailAddress(email),
                    "Confirm your email",
                    $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                AddSuccessMessage("Verification email sent. Please check your email.");
            }

            if (model.ChangeEmailAddress)
            {
                var user = await _userManager.GetUserAsync(User);


                if (model.NewEmail != user.Email)
                {
                    var userId = await _userManager.GetUserIdAsync(user);

                    var code = await _userManager.GenerateChangeEmailTokenAsync(user, model.NewEmail);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Action("Change", "ConfirmEmail", new
                    {
                        area = "",
                        userId, code, email = model.NewEmail
                    }, Request.Scheme);
                    await _emailSender.SendEmailAsync(
                        new MailAddress(model.NewEmail),
                        "Confirm your email",
                        $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    AddSuccessMessage("Confirmation link to change email sent. Please check your email.");

                    return(View(await BuildViewModel()));
                }

                AddFailureMessage("Your email is unchanged.");

                return(View(await BuildViewModel()));
            }

            return(View(await BuildViewModel(model)));
        }
        public DemandPasswordResetModel()
        {
            Title = "demand_password_reset_title";

            EmailInput = new EmailInputModel("Email", "email", true);
        }