Example #1
0
        public async Task SendFullEmail()
        {
            User user = new User();

            user.Email      = "*****@*****.**";
            user.Preference = new Preference
            {
                Languages = new List <string> {
                    "Python"
                },
                Topics = new List <string> {
                    "Machine Learning"
                },
                IsBeginner = false,
                Sizes      = new List <SizeEnum.Size> {
                    SizeEnum.Size.Medium
                }
            };

            var dic = await _githubEngine.GetValidIssues(user);

            _emailEngine.CreateEmail(dic);
            _emailEngine.SendEmail(user);
            Assert.Pass();
        }
Example #2
0
        public void TestEmailEngine()
        {
            EmailEngine ee   = new EmailEngine();
            User        user = new User();

            user.Email = "*****@*****.**";
            ee.SendEmail(user);
        }
Example #3
0
        public async Task SendFullEmail()
        {
            User user = new User();

            user.Email = "*****@*****.**";

            var repositories = await _githubAccessor.GetPublicRepositoriesAsync();

            //repositories = _githubEngine.FilterRepositories(repositories, user);
            var dic = await _githubEngine.CreateRepositoryIssueDictionary(repositories);

            _emailEngine.CreateEmail(dic);
            _emailEngine.SendEmail(user);
            Assert.Pass();
        }
Example #4
0
        public ActionResult Contact(ContactViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var title   = "Message for GuruIn.NET";
                    var subject = string.Format("Message from {0} for GuruIn.NET", model.Name);

                    var template = EmailEngine.GetTemplate("contact-us-template");
                    var body     = template.Replace("*|MC:TITLE|*", title)
                                   .Replace("*|MC:SUBJECT|*", subject)
                                   .Replace("*|MC:EMAILTOBROWSERLINK|*", "http://www.GuruIn.NET")
                                   .Replace("{0}", model.Name)
                                   .Replace("{1}", model.Email)
                                   .Replace("{2}", model.Message.Replace("\r\n", "<br/>").Replace("\n", "<br/>").Replace("\r", "<br/>"))
                                   .Replace("*|CURRENT_YEAR|*", DateTime.Now.Year.ToString())
                                   .Replace("*|LIST:COMPANY|*", "GuruIn.NET");

                    var fromTo = ConfigManager.Get <string>("SmtpUserName");

                    var result = EmailEngine.SendEmail(fromTo, "GuruIn.NET", fromTo, subject, subject, body, cc: (model.CopyUser && !string.IsNullOrWhiteSpace(model.Email) ? model.Email : null));
                    if (result)
                    {
                        Session["USER_MESSAGE"]          = "Your message has been successfully sent. Thank you.";
                        Session["USER_MESSAGE_SEVERITY"] = "Success";
                        Session["USER_MESSAGE_TITLE"]    = "Message Sent";

                        return(RedirectToAction("Index"));
                    }
                }
                catch (Exception ex)
                {
                    Session["USER_MESSAGE"]          = "Sorry, there was an error sending the message. Please try again later.";
                    Session["USER_MESSAGE_SEVERITY"] = "Error";

                    _log.Error("HomeController - Contact", ex);
                }
            }

            return(View(model));
        }
        private bool NotifyNewComment(Comment newComment, int postId)
        {
            try
            {
                var domain      = Request.Url.OriginalString.Replace(Request.Url.PathAndQuery, string.Empty);
                var postLink    = domain + "/Blog/Post/" + postId;
                var commentLink = domain + "/Blog/Post/" + postId + "#comment-" + newComment.Id;
                var deleteLink  = domain + "/Blog/DeleteComment/" + newComment.Id + "/" + DeleteCommentCode + "?postId=" + postId;

                var title   = "New Comment on GuruIn.NET Blog";
                var subject = "Review a new comment on GuruIn.NET Blog";

                var template = EmailEngine.GetTemplate("new-comment-template");
                var body     = template.Replace("*|MC:TITLE|*", title)
                               .Replace("*|MC:SUBJECT|*", subject)
                               .Replace("*|MC:EMAILTOBROWSERLINK|*", "http://www.GuruIn.NET")
                               .Replace("{0}", newComment.Name)
                               .Replace("{1}", newComment.Email)
                               .Replace("{2}", newComment.Content.Replace("\r\n", "<br/>").Replace("\n", "<br/>").Replace("\r", "<br/>"))
                               .Replace("{3}", postLink)
                               .Replace("{4}", commentLink)
                               .Replace("{5}", deleteLink)
                               .Replace("*|CURRENT_YEAR|*", DateTime.Now.Year.ToString())
                               .Replace("*|LIST:COMPANY|*", "GuruIn.NET");

                var fromTo = ConfigManager.Get <string>("SmtpUserName");

                var result = EmailEngine.SendEmail(fromTo, "GuruIn.NET", fromTo, subject, subject, body);
                return(result);
            }
            catch (Exception ex)
            {
                _log.Error("BlogsController - NotifyNewComment", ex);
                return(false);
            }
        }
Example #6
0
        public HttpResponseMessage Post([FromBody] ContactModel model)
        {
            HttpResponseMessage responseMessage = new HttpResponseMessage();

            responseMessage.StatusCode = HttpStatusCode.OK;

            #region Field Validation

            ErrorsManager errorsManager = new ErrorsManager();
            if (string.IsNullOrEmpty(model.FirstName))
            {
                errorsManager.AddError(new ValidationException("First name is empty.", "FirstName"));
            }
            if (string.IsNullOrEmpty(model.LastName))
            {
                errorsManager.AddError(new ValidationException("Last name is empty.", "LastName"));
            }
            if (string.IsNullOrEmpty(model.Company))
            {
                errorsManager.AddError(new ValidationException("Company is empty.", "Company"));
            }

            if (errorsManager.HasErrors)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(errorsManager.ToValidationString())
                });
            }
            #endregion
            try
            {
                ContactUsOpsMgmt.InsertItem(model.FirstName, model.LastName, model.Address, model.Address2, model.Company,
                                            model.City, model.State, model.Zip, model.Company, model.Phone, model.Message, model.ReasonsForContact, model.HasOptedForSubscription);

                EmailEngine emailEngine = new EmailEngine(string.Empty, "ContactTemplate", "A new contact request has been submitted.");
                emailEngine.AddAdminReceivers();
                emailEngine.AddMergingField("FirstName", model.FirstName);
                emailEngine.AddMergingField("LastName", model.LastName);
                emailEngine.AddMergingField("Address", model.Address);
                emailEngine.AddMergingField("Address2", model.Address);
                emailEngine.AddMergingField("Company", model.Company);
                emailEngine.AddMergingField("City", model.City);
                emailEngine.AddMergingField("State", model.State);
                emailEngine.AddMergingField("Zip", model.Zip);
                emailEngine.AddMergingField("Phone", model.Phone);
                emailEngine.AddMergingField("Country", model.Country);
                emailEngine.AddMergingField("Message", model.Message);
                emailEngine.AddMergingField("ReasonsForContact", model.ReasonsForContact);
                emailEngine.AddMergingField("HasOptedForSubscription", model.HasOptedForSubscription);


                emailEngine.SendEmail();

                return(responseMessage);
            }
            catch (Exception ex)
            {
                Log.Write(ex, System.Diagnostics.TraceEventType.Error);
                errorsManager.AddError(new ValidationException("Unknown error has occured.", "General"));
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(errorsManager.ToValidationString())
                });
            }
        }
        public HttpResponseMessage Post([FromBody] ImageSubmissionModel model)
        {
            HttpResponseMessage responseMessage = new HttpResponseMessage();

            responseMessage.StatusCode = HttpStatusCode.OK;

            #region Field Validation

            ErrorsManager errorsManager = new ErrorsManager();
            if (string.IsNullOrEmpty(model.FullName))
            {
                errorsManager.AddError(new ValidationException("Name is empty.", "FullName"));
            }
            if (string.IsNullOrEmpty(model.Company))
            {
                errorsManager.AddError(new ValidationException("Company is empty.", "Company"));
            }
            if (string.IsNullOrEmpty(model.Email))
            {
                errorsManager.AddError(new ValidationException("Email is empty.", "Email"));
            }
            else
            {
                if (!(Regex.IsMatch(model.Email, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase)))
                {
                    errorsManager.AddError(new ValidationException("Email is not valid.", "Email"));
                }
            }
            if (errorsManager.HasErrors)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(errorsManager.ToValidationString())
                });
            }
            #endregion
            try
            {
                ImageSubmissionOpsMgmt.InsertItem(model.FullName, model.Company, model.PhoneNumber, model.Email, model.Comments);

                EmailEngine emailEngine = new EmailEngine(string.Empty, "ImageSubmissionTemplate", "A new image upload request has been submitted.");
                emailEngine.AddAdminReceivers();
                emailEngine.AddMergingField("FullName", model.FullName);
                emailEngine.AddMergingField("Company", model.Company);
                emailEngine.AddMergingField("PhoneNumber", model.PhoneNumber);
                emailEngine.AddMergingField("Email", model.Email);
                emailEngine.AddMergingField("Content", model.Comments);


                emailEngine.SendEmail();

                return(responseMessage);
            }
            catch (Exception ex)
            {
                Log.Write(ex, System.Diagnostics.TraceEventType.Error);
                errorsManager.AddError(new ValidationException("Unknown error has occured.", "General"));
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(errorsManager.ToValidationString())
                });
            }
        }