Example #1
0
        public async Task SendEmailAsync(Postal.Email emailData)
        {
            MailMessage message = await _emailService.CreateMailMessageAsync(emailData);

            message.From = new MailAddress(_emailOptions.FromAddress);
            await SendEmailAsync(message);
        }
Example #2
0
        public async Task<ActionResult> Contact(Models.ContactViewModel contact)
        {
            if (ModelState.IsValid)
            {
                var currentTime = DateTime.UtcNow;
                var elapsedTime = currentTime - contact.TimeSent;
                bool spamFieldFull = !string.IsNullOrEmpty(contact.Check);

                dynamic email = new Email("ContactForm");
                email.From = contact.Email;
                email.CurrentTime = currentTime;
                email.Name = contact.Name;
                email.Title = contact.Title;
                email.Phone = contact.Phone;
                email.Company = contact.Company;
                email.Address = contact.Address;
                email.City = contact.City;
                email.State = contact.State;
                email.Zip = contact.Zip;
                email.Country = contact.Country;
                email.Comments = contact.Comments;
                email.Elapsed = elapsedTime;
                email.SpamFieldFull = spamFieldFull;

                await email.SendAsync();
                return RedirectToAction("ContactSuccess");                                
            }

            return View(contact);
        }
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    string confirmationToken =
                        WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new { Email = model.Email }, true);
                    dynamic email = new Email("RegEmail");
                    email.To = model.Email;
                    email.UserName = model.UserName;
                    email.ConfirmationToken = confirmationToken;
                    email.Send();

                    return RedirectToAction("RegisterStepTwo", "Account");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Example #4
0
 public ActionResult Simple()
 {
     dynamic email = new Email("Simple");
     email.Date = DateTime.UtcNow.ToString();
     
     return new EmailViewResult(email);
 }
Example #5
0
        public void Send(string content)
        {
            _smtpClient = new SmtpClient(Address, Port);
            _smtpClient.Credentials = new NetworkCredential(Account, Password);
            _smtpClient.EnableSsl = false;
            MailMessage mailMessage = new MailMessage();
            mailMessage.BodyEncoding = Encoding.UTF8;
            mailMessage.From = new MailAddress(From, SenderName, Encoding.UTF8);
            mailMessage.To.Add(To);
            mailMessage.Body = content;
            mailMessage.Subject = Subject;
            _smtpClient.Send(mailMessage);


            dynamic email = new Email("Example");
            email.To = "*****@*****.**";
            email.Send();


            var viewsPath = Path.GetFullPath(@"..\..\Views");

            var engines = new ViewEngineCollection();
            engines.Add(new FileSystemRazorViewEngine(viewsPath));

            var service = new EmailService(engines);
            dynamic email = new Email("Test");

            // Will look for Test.cshtml or Test.vbhtml in Views directory.
            email.Message = "Hello, non-asp.net world!";
            service.Send(email);
           // RESTORE DATABASE is terminating abnormally.
        }
Example #6
0
 public ActionResult MultiPart()
 {
     dynamic email = new Email("MultiPart");
     email.Date = DateTime.UtcNow.ToString();
     
     return new EmailViewResult(email);
 }
Example #7
0
        public Task SendAsync(IdentityMessage message)
        {
            Postal.EmailService emailService = new Postal.EmailService(ViewEngines.Engines);

            var fromEmail = SecureSettings.GetValue("smtp:From");
            var host = SecureSettings.GetValue("smtp:Host");
            if (!string.IsNullOrEmpty(host))
            {
                emailService = new Postal.EmailService(ViewEngines.Engines, () => CreateMySmtpClient());
            }

            dynamic email = new Email("IdentityMessageService");
            email.To = message.Destination;
            if (!string.IsNullOrEmpty(fromEmail))
            {
                email.From = fromEmail;
            }
            else
            {
                fromEmail = ConfigurationManager.AppSettings["NoReplyEmail"];
                if (string.IsNullOrEmpty(fromEmail)) fromEmail = "*****@*****.**";
                email.From = fromEmail;
            }

            email.Subject = message.Subject;
            email.Body = message.Body;

            return emailService.SendAsync(email);

               // return email.SendAsync();

            //return Task.FromResult(0);
        }
Example #8
0
        //
        // GET: /Manage/Index
        public async Task<ActionResult> Index(ManageMessageId? message, string requirements)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            var userId = User.Identity.GetUserId();
            var model = new IndexViewModel
            {
                HasPassword = HasPassword(),
                PhoneNumber = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
            };
            if (requirements != null)
            {
                string session_user = User.Identity.GetUserId();
                AspNetUsers anu;
                TempData["succMess"] = "Your message was sent to administrator!";

                dynamic email = new Email("View");
                email.to = "*****@*****.**";
                email.message = requirements;
                anu = db.AspNetUsers.Single(a => a.Id == session_user);
                email.ID = anu.Email;
                email.Send();
            }
            return View(model);
        }
		public async Task NotifyPlayerForAttention(string userId, string subject, string message, string gameId)
		{
			var userClaims = await _userManager.GetClaimsAsync(userId);

			var emailClaim = userClaims.FirstOrDefault(claim => claim.Type == ClaimTypes.Email);

			if (emailClaim == null)
				return;

			dynamic email = new Email("HailUser");
			email.To = emailClaim.Value;
			email.Subject = subject;
			email.Message = message;
            email.GameId = gameId;

			var service = new Postal.EmailService(System.Web.Mvc.ViewEngines.Engines, () =>
			{
				if (string.IsNullOrWhiteSpace(SMTPServer) || string.IsNullOrWhiteSpace(SMTPUsername) || string.IsNullOrWhiteSpace(SMTPPassword) || string.IsNullOrWhiteSpace(SMTPPort))
				{
					return new SmtpClient();
				}

				return new SmtpClient(SMTPServer, int.Parse(SMTPPort))
				{
					EnableSsl = true,
					Credentials = new NetworkCredential(SMTPUsername, SMTPPassword)
				};
			});

			await service.SendAsync(email);
		}
        public ActionResult Contact(ContactModel model)
        {
            // Build the contact email using a dynamic object for flexibility
            dynamic email = new Email("Contact");
            email.To = ConfigurationManager.AppSettings["email:ContactToAddress"];
            email.From = ConfigurationManager.AppSettings["email:ContactFromAddress"];
            email.FirstName = model.FirstName;
            email.LastName = model.LastName;
            email.BusinessType = model.BusinessType;
            email.AddressLine1 = model.AddressLine1;
            email.AddressLine2 = model.AddressLine2;
            email.City = model.City;
            email.State = model.State;
            email.ZipCode = model.ZipCode;
            email.Country = model.Country == "Other" ? model.CountryName : model.Country;
            email.Phone = model.Phone;
            email.Email = model.Email;
            email.Comments = model.Comments;
            email.Send();

            // Set the ShowThanksMessage flag to provide user feedback on the page.
            model.ShowThanksMessage = true;

            return View(model);
        }
Example #11
0
        public void Alternative_views_are_added_to_MailMessage()
        {
            var input = @"
            To: [email protected]
            From: [email protected]
            Subject: Test Subject
            Views: Text, Html";
            var text = @"Content-Type: text/plain

            Hello, World!";
            var html = @"Content-Type: text/html

            <p>Hello, World!</p>";

            var email = new Email("Test");
            var renderer = new Mock<IEmailViewRenderer>();
            renderer.Setup(r => r.Render(email, "Test.Text")).Returns(text);
            renderer.Setup(r => r.Render(email, "Test.Html")).Returns(html);

            var parser = new EmailParser(renderer.Object);
            using (var message = parser.Parse(input, email))
            {
                message.AlternateViews[0].ContentType.ShouldEqual(new ContentType("text/plain; charset=utf-16"));
                var textContent = new StreamReader(message.AlternateViews[0].ContentStream).ReadToEnd();
                textContent.ShouldEqual("Hello, World!");

                message.AlternateViews[1].ContentType.ShouldEqual(new ContentType("text/html; charset=utf-16"));
                var htmlContent = new StreamReader(message.AlternateViews[1].ContentStream).ReadToEnd();
                htmlContent.ShouldEqual("<p>Hello, World!</p>");
            }
        }
Example #12
0
        public static bool SendHKNews(HKNewsPaper paper)
        {
            dynamic email = new Email("~/MailTemplates/HKNews.cshtml");
            email.Model = paper;
            email.Send();

            return true;
        }
Example #13
0
 public static void WelcomeSendPassword(string username, string toaddress, string pass)
 {
     dynamic email = new Email("~/MailTemplates/Teszt.cshtml");
     email.To = toaddress;
     email.UserName = username;
     email.Password = pass;
     email.Send();
 }
Example #14
0
        public void Getting_dynamic_property_reads_from_ViewData()
        {
            var email = new Email("Test");
            email.ViewData["Subject"] = "SubjectValue";

            dynamic email2 = email;
            Assert.Equal("SubjectValue", email2.Subject);
        }
 public void QueueEmail(EmailViewModel emailViewModel)
 {
     dynamic email = new Email("SignUp");
     email.To = emailViewModel.To;
     email.ActivationToken = emailViewModel.ActivationToken;
     email.BaseDomain = configuration.BaseDomain;
     email.Send();
 }
Example #16
0
 public string Render(Email email, string viewName = null)
 {
     viewName = viewName ?? email.ViewName;
     var controllerContext = CreateControllerContext();
     var view = CreateView(viewName, controllerContext);
     var viewOutput = RenderView(view, email.ViewData, controllerContext);
     return viewOutput;
 }
Example #17
0
 /// <summary>
 /// Sends an email using an <see cref="SmtpClient"/>.
 /// </summary>
 /// <param name="email">The email to send.</param>
 public void Send(Email email)
 {
     using (var mailMessage = CreateMailMessage(email))
     using (var smtp = createSmtpClient())
     {
         smtp.Send(mailMessage);
     }
 }
Example #18
0
        public void Dynamic_property_setting_assigns_ViewData_value()
        {
            dynamic email = new Email("Test");
            email.Subject = "SubjectValue";

            var email2 = (Email)email;
            email2.ViewData["Subject"].ShouldEqual("SubjectValue");
        }
        public ActionResult SendSimple()
        {
            dynamic email = new Email("Simple");
            email.Date = DateTime.UtcNow.ToString();
            email.Send();

            return RedirectToAction("Sent", "Home");
        }
Example #20
0
 // GET: Home
 public ActionResult Index()
 {
     dynamic email = new Email("Example");
     email.To = "[email protected], [email protected], [email protected]";
     email.FunnyLink = "http://blog.respag.net";
     email.Fecha = DateTime.Now.ToString(@"dddd, dd \de MMMM \de yyyy");
     email.Send();
     return View();
 }
        public ActionResult ForgotThePassword(LoginViewModel loginModel)
        {
            dynamic email = new Email("ForgotThePassword");
            email.To = "*****@*****.**";
            email.FunnyLink = "Hello Alex :)";
            email.Send();

            return View();
        }
Example #22
0
        public Task UserConfirmationAsync(string receipent, string token)
        {
            dynamic email = new Email("UserConfirmation");
            email.To = receipent;
            email.From = sender;
            email.Url = urlResolver.UserConfirmation(token);

            return emailService.SendAsync(email);
        }
Example #23
0
        public Task ForgotPasswordAsync(string receipent, string token)
        {
            dynamic email = new Email("ForgotPassword");
            email.To = receipent;
            email.From = sender;
            email.Url = urlResolver.ForgotPassword(token);

            return emailService.SendAsync(email);
        }
Example #24
0
        public void Send_creates_EmailService_and_calls_Send()
        {
            var emailService = new Mock<IEmailService>();
            Email.CreateEmailService = () => emailService.Object;
            var email = new Email("Test");

            email.Send();

            emailService.Verify(s => s.Send(email));
        }
            public string Render(Email email, string viewName)
            {
                if(HttpContext.Current == null)
                {
                    HttpContext.Current = new HttpContext(new HttpRequest(String.Empty, Constants.ROOT_URL, String.Empty),
                                                          new HttpResponse(TextWriter.Null));
                }

                return mImplementation.Render(email, viewName);
            }
 public JsonResult ResetUserPassword(string username, string emailAddress)
 {
     var confirmationToken = WebSecurity.GeneratePasswordResetToken(username);
     dynamic email = new Email("ChngPasswordEmail");
     email.To = emailAddress;
     email.UserName = username;
     email.ConfirmationToken = confirmationToken;
     email.Send();
     return Json(new { success = true });
 }
 public ActionResult Contact(string name, string useremail, string title, string message)
 {
     dynamic email = new Email("Contact");
     email.From = useremail;
     email.Name = name;
     email.Title = title;
     email.Message = message;
     email.Send();
     return View();
 }
        public async Task SendAsync(IdentityMessage message)
        {
            dynamic email = new Postal.Email("IdentityMessage");

            email.To      = message.Destination;
            email.Subject = message.Subject;
            email.Body    = message.Body;

            await EmailService.SendAsync(email);
        }
        public Task SendAsync(IdentityMessage message)
        {
            dynamic email = new Email("AuthEmail");
            email.To = message.Destination;
            email.Body = message.Body;
            email.Subject = message.Subject;

            email.Send();

            return Task.FromResult(0);
        }
Example #30
0
        public ActionResult Send(string to, string subject, string message)
        {
            dynamic email = new Email("HtmlOnly");
            email.Subject = "An HTML email";
            email.Date = DateTime.UtcNow;
            // Send the email - this uses a default System.Net.Mail.SmtpClient
            // and web.config settings to send the email.
            emailService.Send(email);

            return RedirectToAction("Sent");
        }
Example #31
0
        public ActionResult Send(string to, string subject, string message)
        {
            // This will look for a view in "~/Views/Emails/Complex.cshtml".
            dynamic email = new Email("Multipart");
            email.Title = "A complex email with alternative views";
            // Send the email - this uses a default System.Net.Mail.SmtpClient
            // and web.config settings to send the email.
            emailService.Send(email);

            return RedirectToAction("Sent");
        }
Example #32
0
 public static void RegistrationConfirmationEmail(RegistrationConfirmationEmail input)
 {
     dynamic email = new Email("RegistrationConfirmation");
     email.To = input.To;
     email.From = input.From;
     email.Subject = input.Subject;
     email.Cc = input.Cc;
     email.Bcc = input.Bcc;
     email.ConfirmationLink = input.ConfirmationLink;
     email.FullName = input.FullName;
     email.Send();
 }
        protected async Task SendEmailAsync(string templateKey, string email, string subject, string htmlMessage, string plainTextMessage)
        {
            if (Mailer == null)
            {
                throw new NullMailerException();
            }

            dynamic message = new Postal.Email(templateKey);

            message.To               = email;
            message.HtmlMessage      = htmlMessage;
            message.PlainTextMessage = plainTextMessage;

            await Mailer.SendAsync(message);
        }
Example #34
0
        public void SendEmail(string templateAddress, Postal.Email model)
        {
            // default was:
            //@"..\..\Views"
            var viewsPath = Path.GetFullPath(templateAddress);

            var engines = new ViewEngineCollection();

            engines.Add(new FileSystemRazorViewEngine(viewsPath));

            var service = new EmailService(engines);

            dynamic email = model;

            // Will look for Test.cshtml or Test.vbhtml in Views directory.
            service.Send(email);
        }
Example #35
0
        public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByNameAsync(model.Email);

                if (user == null)
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return(View("ForgotPasswordConfirmation"));
                }

                // Check if email confirm required
                if (CacheHelper.Settings.EmailConfirmedRequired && !(await UserManager.IsEmailConfirmedAsync(user.Id)))
                {
                    return(View("ForgotPasswordConfirmation"));
                }

                // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                //Send an email with this link
                string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

                var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>");

                // return RedirectToAction("ForgotPasswordConfirmation", "Account");

                var emailTemplateQuery = await _emailTemplateService.Query(x => x.Slug.ToLower() == "forgotpassword").SelectAsync();

                var emailTemplate = emailTemplateQuery.Single();

                dynamic email = new Postal.Email("Email");
                email.To          = user.Email;
                email.From        = CacheHelper.Settings.EmailAddress;
                email.Subject     = emailTemplate.Subject;
                email.Body        = emailTemplate.Body;
                email.CallbackUrl = callbackUrl;
                EmailHelper.SendEmail(email);

                return(RedirectToAction("ForgotPasswordConfirmation", "Account"));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Example #36
0
        public async Task <ActionResult> EmailSender(EmailSenderViewModel model)
        {
            Postal.Email email = null;
            string       callbackUrl;

            switch (model.SelectedEmailTypeId)
            {
            case (int)EmailTypeEnum.Welcome:
                callbackUrl = "http://localhost:8081/Account/ConfirmEmail?userId=0000000000&code=0000000000";
                email       = await _postalEmailHelper.SendConfirmationEmailAsync(model.Email, "Miguel Soriano", "password", callbackUrl, false);

                break;

            case (int)EmailTypeEnum.ReSendConfirmation:
                callbackUrl = "http://localhost:8081/Account/ConfirmEmail?userId=0000000000&code=0000000000";
                email       = await _postalEmailHelper.ResendConfirmationEmailAsync(model.Email, callbackUrl, false);

                break;

            case (int)EmailTypeEnum.ResetPassword:
                callbackUrl = "http://localhost:8081/Account/ConfirmEmail?userId=0000000000&code=0000000000";
                email       = await _postalEmailHelper.SendResetPasswordEmailAsync(model.Email, "Miguel Soriano", callbackUrl, false);

                break;

            case (int)EmailTypeEnum.PetShare:
                callbackUrl = "http://localhost:8081/Account/ConfirmEmail?userId=0000000000&code=0000000000";
                email       = await _postalEmailHelper.SendShareEmailEmailAsync(model.Email, "Marti", callbackUrl, false);

                break;
            }

            switch (model.SelectedViewTypeId)
            {
            case (int)EmailViewerTypeEnum.Browser:
                return(new EmailViewResult(email));

            case (int)EmailViewerTypeEnum.Email:
                email.Send();
                break;
            }

            this.SetAlertMessageInTempData(Models.Shared.AlertMessageTypeEnum.Success, "El correo fue enviado.");
            return(RedirectToAction("EmailSender"));
        }
Example #37
0
        public async Task <ActionResult> EmailTemplateTest(int id)
        {
            var emailTemplate = await _emailTemplateService.FindAsync(id);

            if (emailTemplate == null)
            {
                return(new HttpNotFoundResult());
            }

            dynamic email = new Postal.Email("Email");

            email.To      = CacheHelper.Settings.EmailContact;
            email.From    = CacheHelper.Settings.EmailContact;
            email.Subject = "[[[Testing]]] - " + emailTemplate.Subject;
            email.Body    = emailTemplate.Body;

            EmailHelper.SendEmail(email);

            TempData[TempDataKeys.UserMessage] = "[[[Message sent succesfully!]]]";

            return(RedirectToAction("EmailTemplateUpdate", new { id = id }));
        }
        public virtual async Task <ActionResult> Index(ContactMessageModel model)
        {
            if (ModelState.IsValid)
            {
                dynamic email = new Postal.Email("ContactMessage");
                email.To        = ConfigurationManager.AppSettings["ContactUsClient"];
                email.Cc        = ConfigurationManager.AppSettings["ContactUsInternal"];
                email.Subject   = ConfigurationManager.AppSettings["ContactUsSubject"];
                email.FirstName = model.FirstName;
                email.LastName  = model.LastName;
                email.Email     = model.Email;
                email.Title     = model.Subject;
                email.Message   = model.Body;

                await EmailService.SendAsync(email);

                ViewBag.Message = "Thanks for your feedback.";

                return(View(MVC.Shared.Views.Info));
            }

            return(View(model));
        }
Example #39
0
        IEnumerable <AlternateView> CreateAlternativeViews(string deliminatedViewNames, Email email)
        {
            var viewNames = deliminatedViewNames.Split(new[] { ',', ' ', ';' }, StringSplitOptions.RemoveEmptyEntries);

            return(from viewName in viewNames
                   select CreateAlternativeView(email, viewName));
        }
Example #40
0
        public async Task <IdentityResult> RegisterAccount(RegisterViewModel model)
        {
            var user = new ApplicationUser
            {
                UserName       = model.Email,
                Email          = model.Email,
                FirstName      = model.FirstName,
                LastName       = model.LastName,
                PhoneNumber    = model.Phone,
                Gender         = model.Gender,
                CountryID      = model.CountryID,
                RegisterDate   = DateTime.Now,
                RegisterIP     = System.Web.HttpContext.Current.Request.GetVisitorIP(),
                LastAccessDate = DateTime.Now,
                LastAccessIP   = System.Web.HttpContext.Current.Request.GetVisitorIP()
            };

            var result = await UserManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                #region Mensaje
                // Send Message
                var roleAdministrator = await RoleManager.FindByNameAsync(BeYourMarket.Model.Enum.Enum_UserType.Administrator.ToString());

                var administrator = roleAdministrator.Users.FirstOrDefault();

                var message = new MessageSendModel()
                {
                    UserFrom = administrator.UserId,
                    UserTo   = user.Id,
                    Subject  = HttpContext.ParseAndTranslate(string.Format("[[[Welcome to {0}!]]]", CacheHelper.Settings.Name)),
                    Body     = HttpContext.ParseAndTranslate(string.Format("[[[Hi, Welcome to {0}! I am happy to assist you if you has any questions.]]]", CacheHelper.Settings.Name))
                };

                await MessageHelper.SendMessage(message);

                #endregion

                #region Correo
                // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                // Send an email with this link
                string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                var urlHelper   = new UrlHelper(System.Web.HttpContext.Current.Request.RequestContext);
                var callbackUrl = urlHelper.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: System.Web.HttpContext.Current.Request.Url.Scheme);
                await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); var emailTemplateQuery = await _emailTemplateService.Query(x => x.Slug.ToLower() == "signup").SelectAsync();

                var emailTemplate = emailTemplateQuery.FirstOrDefault();

                if (emailTemplate != null)
                {
                    dynamic email = new Postal.Email("Email");
                    email.To          = user.Email;
                    email.From        = CacheHelper.Settings.EmailAddress;
                    email.Subject     = emailTemplate.Subject;
                    email.Body        = emailTemplate.Body;
                    email.CallbackUrl = callbackUrl;
                    EmailHelper.SendEmail(email);
                }
                #endregion
            }

            return(result);
        }