void btnOptInUsers_Click(object sender, EventArgs e) { if (letterInfoGuid == Guid.Empty) { return; } if (currentUser == null) { return; } LetterOptInTask optInTask = new LetterOptInTask(); optInTask.SiteGuid = CurrentSite.SiteGuid; optInTask.QueuedBy = currentUser.UserGuid; optInTask.LetterInfoGuid = letterInfoGuid; optInTask.ExcludeIfAnyUnsubscribeHx = WebConfigSettings.NewsletterExcludeAllPreviousOptOutsWhenOptingInUsers; optInTask.QueueTask(); string redirectUrl = SiteRoot + "/eletter/OptInUsersDialog.aspx?l=" + letterInfoGuid.ToString() + "&t=" + optInTask.TaskGuid.ToString(); WebTaskManager.StartOrResumeTasks(); WebUtils.SetupRedirect(this, redirectUrl); }
private void SendRejectionNotification( SmtpSettings smtpSettings, SiteSettings siteSettings, DateTime?requestedUtc, SiteUser rejectingUser, string rejectionReason ) { string requestedDate = string.Empty; if (requestedUtc.HasValue) { requestedDate = DateTimeHelper.GetLocalTimeString(requestedUtc, SiteUtils.GetUserTimeZone(), SiteUtils.GetUserTimeOffset()); } StringBuilder message = new StringBuilder(); message.Append(MessageTemplate.GetMessage("ApprovalRequestRejectionNotification")); message.Replace("{Title}", news.Title); message.Replace("{ApprovalRequestedDate}", requestedDate); message.Replace("{RejectionReason}", rejectionReason); message.Replace("{RejectedBy}", rejectingUser.Name); if (!Email.IsValidEmailAddressSyntax(news.UserEmail)) { //invalid address log it log.Error("Failed to send workflow rejection message, invalid recipient email " + news.UserEmail + " message was " + message.ToString()); return; } EmailMessageTask messageTask = new EmailMessageTask(smtpSettings); messageTask.SiteGuid = siteSettings.SiteGuid; messageTask.EmailFrom = siteSettings.DefaultEmailFromAddress; messageTask.EmailFromAlias = siteSettings.DefaultFromEmailAlias; messageTask.EmailReplyTo = rejectingUser.Email; messageTask.EmailTo = news.UserEmail; messageTask.UseHtml = true; messageTask.Subject = MessageTemplate.GetMessage("ApprovalRequestRejectionNotificationSubject").Replace("{SiteName}", siteSettings.SiteName); messageTask.HtmlBody = message.ToString(); messageTask.QueueTask(); WebTaskManager.StartOrResumeTasks(); //Email.Send( // smtpSettings, // siteSettings.DefaultEmailFromAddress, // siteSettings.DefaultFromEmailAlias, // rejectingUser.Email, // news.UserEmail, // string.Empty, // string.Empty, // MessageTemplate.GetMessage("ApprovalRequestRejectionNotificationSubject").Replace("{SiteName}", siteSettings.SiteName), // message.ToString(), // false, // Email.PriorityNormal); }
public override void UserRegisteredHandler(object sender, UserRegisteredEventArgs e) { if (e == null) { return; } if (e.SiteUser == null) { return; } SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings(); log.Debug("NotifyUserRegisteredHandler called for new user " + e.SiteUser.Email); if (HttpContext.Current == null) { return; } if (siteSettings.UseSecureRegistration) { return; } EmailTemplate template = EmailTemplate.Get(siteSettings.SiteId, "RegisterEmailNotification"); if (template == null || template.Guid == Guid.Empty) { return; } string fromEmailAlias = (template.FromName.Length > 0 ? template.FromName : siteSettings.DefaultFromEmailAlias); SmtpSettings smtpSettings = SiteUtils.GetSmtpSettings(); string toEmail = e.SiteUser.Email; if (template.ToAddresses.Length > 0) { toEmail += ";" + template.ToAddresses; } EmailMessageTask messageTask = new EmailMessageTask(smtpSettings); messageTask.SiteGuid = siteSettings.SiteGuid; messageTask.EmailFrom = siteSettings.DefaultEmailFromAddress; messageTask.EmailFromAlias = (template.FromName.Length > 0 ? template.FromName : siteSettings.DefaultFromEmailAlias); messageTask.EmailReplyTo = template.ReplyToAddress; messageTask.EmailTo = toEmail; messageTask.EmailCc = template.CcAddresses; messageTask.EmailBcc = template.BccAddresses; messageTask.UseHtml = true; messageTask.Subject = template.Subject.Replace("{Email}", e.SiteUser.Email).Replace("{FirstName}", e.SiteUser.FirstName).Replace("{LastName}", e.SiteUser.LastName); messageTask.HtmlBody = template.HtmlBody.Replace("{SiteName}", siteSettings.SiteName).Replace("{Email}", e.SiteUser.Email).Replace("{FirstName}", e.SiteUser.FirstName).Replace("{LastName}", e.SiteUser.LastName).Replace("{Username}", e.SiteUser.Name).Replace("{Password}", e.SiteUser.Password); messageTask.QueueTask(); WebTaskManager.StartOrResumeTasks(); }
public static void SendCommentNotification(string toEmail) { //added this due to product comment spam and need to be able to ban the ip of the spammer StringBuilder messageToken = new StringBuilder(); //messageToken.Append(basePage.SiteRoot + product.Url.Replace("~", string.Empty)); messageToken.Append("\n\nHTTP_USER_AGENT: " + HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"] + "\n"); messageToken.Append("HTTP_HOST: " + HttpContext.Current.Request.ServerVariables["HTTP_HOST"] + "\n"); messageToken.Append("REMOTE_HOST: " + HttpContext.Current.Request.ServerVariables["REMOTE_HOST"] + "\n"); messageToken.Append("REMOTE_ADDR: " + SiteUtils.GetIP4Address() + "\n"); messageToken.Append("LOCAL_ADDR: " + HttpContext.Current.Request.ServerVariables["LOCAL_ADDR"] + "\n"); messageToken.Append("HTTP_REFERER: " + HttpContext.Current.Request.ServerVariables["HTTP_REFERER"] + "\n"); SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings(); if ((toEmail.Length > 0) && (Email.IsValidEmailAddressSyntax(toEmail))) { EmailTemplate template = EmailTemplate.Get(siteSettings.SiteId, "ProductCommentNotification"); string fromAddress = siteSettings.DefaultEmailFromAddress; string fromAlias = template.FromName; if (fromAlias.Length == 0) { fromAlias = siteSettings.DefaultFromEmailAlias; } if (template.ToAddresses.Length > 0) { toEmail += ";" + template.ToAddresses; } SmtpSettings smtpSettings = SiteUtils.GetSmtpSettings(); StringBuilder message = new StringBuilder(); message.Append(template.HtmlBody); message.Replace("{SiteName}", siteSettings.SiteName); message.Replace("{Message}", messageToken.ToString()); string subject = template.Subject.Replace("{SiteName}", siteSettings.SiteName); EmailMessageTask messageTask = new EmailMessageTask(smtpSettings); messageTask.SiteGuid = siteSettings.SiteGuid; messageTask.EmailFrom = fromAddress; messageTask.EmailFromAlias = fromAlias; messageTask.EmailReplyTo = template.ReplyToAddress; messageTask.EmailTo = toEmail; messageTask.EmailCc = template.CcAddresses; messageTask.EmailBcc = template.BccAddresses; messageTask.UseHtml = true; messageTask.Subject = subject; messageTask.HtmlBody = message.ToString(); messageTask.QueueTask(); WebTaskManager.StartOrResumeTasks(); } }
private bool sendmail(string authorname, string mailto) { try { EmailTemplate template = EmailTemplate.Get(siteSettings.SiteId, "EmailRegisterAuthor", WorkingCulture.LanguageId); string subjectEmail = template.Subject.Replace("{SiteName}", siteSettings.SiteName); System.Text.StringBuilder messageEmail = new System.Text.StringBuilder(); messageEmail.Append(template.HtmlBody); messageEmail.Replace("{Name}", authorname); string fromAddress = siteSettings.DefaultEmailFromAddress; string fromAlias = template.FromName; if (fromAlias.Length == 0) { fromAlias = siteSettings.DefaultFromEmailAlias; } string emailTo = (template.ToAddresses.Length > 0 ? ";" + template.ToAddresses : ""); string emailCc = template.CcAddresses; string emailBcc = template.BccAddresses; string emailReplyTo = (template.ReplyToAddress.Length > 0 ? ";" + template.ReplyToAddress : ""); SmtpSettings smtpSettings = SiteUtils.GetSmtpSettings(); EmailMessageTask messageTask = new EmailMessageTask(smtpSettings); messageTask.SiteGuid = siteSettings.SiteGuid; messageTask.EmailFrom = fromAddress; messageTask.EmailFromAlias = fromAlias; messageTask.EmailReplyTo = emailReplyTo; messageTask.EmailTo = mailto; messageTask.EmailCc = emailCc; messageTask.EmailBcc = emailBcc; messageTask.Subject = subjectEmail; messageTask.UseHtml = true; messageTask.HtmlBody = messageEmail.ToString(); messageTask.QueueTask(); WebTaskManager.StartOrResumeTasks(); return(true); } catch (Exception) { return(false); } }
void btnStartTasks_Click(object sender, EventArgs e) { WebTaskManager.StartOrResumeTasks(); WebUtils.SetupRedirect(this, Request.RawUrl); }
//public static Module FindAuthorModule(PageSettings currentPage) //{ // foreach (Module m in currentPage.Modules) // { // if (m.FeatureGuid == Author.FeatureGuid) return m; // if (m.ControlSource == "Author/AuthorModule.ascx") return m; // } // return null; //} public static void SendCommentNotification( SmtpSettings smtpSettings, Guid siteGuid, string fromAddress, string fromAlias, string toEmail, string replyEmail, string ccEmail, string bccEmail, string subject, string messageTemplate, string siteName, string messageToken) { if (string.IsNullOrEmpty(messageTemplate)) { return; } StringBuilder message = new StringBuilder(); message.Append(messageTemplate); message.Replace("{SiteName}", siteName); message.Replace("{Message}", messageToken); subject = subject.Replace("{SiteName}", siteName); //try //{ // Email.SendEmail( // smtpSettings, // fromAddress, // toEmail, // replyEmail, // ccEmail, // bccEmail, // subject, // message.ToString(), // true, // "Normal"); //} //catch (Exception ex) //{ // log.Error("Error sending email from address was " + fromAddress + " to address was " + toEmail, ex); //} EmailMessageTask messageTask = new EmailMessageTask(smtpSettings); messageTask.SiteGuid = siteGuid; messageTask.EmailFrom = fromAddress; messageTask.EmailFromAlias = fromAlias; messageTask.EmailReplyTo = replyEmail; messageTask.EmailTo = toEmail; messageTask.EmailCc = ccEmail; messageTask.EmailBcc = bccEmail; messageTask.UseHtml = true; messageTask.Subject = subject; messageTask.HtmlBody = message.ToString(); messageTask.QueueTask(); WebTaskManager.StartOrResumeTasks(); }
void btnSendToList_Click(object sender, EventArgs e) { SaveLetter(); if (!LetterIsValidForSending()) { return; } if (letter.SendCompleteUtc > DateTime.MinValue) { return; } // TODO: implement approval process letter.ApprovedBy = currentUser.UserGuid; letter.IsApproved = true; string baseUrl = WebUtils.GetHostRoot(); if (WebConfigSettings.UseFoldersInsteadOfHostnamesForMultipleSites) { // in folder based sites the relative urls in the editor will already have the folder name // so we want to use just the raw site root not the navigation root baseUrl = WebUtils.GetSiteRoot(); } string content = SiteUtils.ChangeRelativeUrlsToFullyQualifiedUrls(baseUrl, WebUtils.GetSiteRoot(), letter.HtmlBody); letter.HtmlBody = content; SaveLetter(); letter.TrackSendClicked(); SmtpSettings smtpSettings = GetSmtpSettings(); LetterSendTask letterSender = new LetterSendTask { SiteGuid = siteSettings.SiteGuid, QueuedBy = currentUser.UserGuid, LetterGuid = letter.LetterGuid, UnsubscribeLinkText = Resource.NewsletterUnsubscribeLink, ViewAsWebPageText = Resource.NewsletterViewAsWebPageLink, UnsubscribeUrl = SiteRoot + "/eletter/Unsubscribe.aspx", NotificationFromEmail = siteSettings.DefaultEmailFromAddress, NotifyOnCompletion = true, NotificationToEmail = currentUser.Email, User = smtpSettings.User, Password = smtpSettings.Password, Server = smtpSettings.Server, Port = smtpSettings.Port, RequiresAuthentication = smtpSettings.RequiresAuthentication, UseSsl = smtpSettings.UseSsl, PreferredEncoding = smtpSettings.PreferredEncoding, TaskUpdateFrequency = 65, MaxToSendPerMinute = WebConfigSettings.NewsletterMaxToSendPerMinute }; if (letterInfo.AllowArchiveView) { letterSender.WebPageUrl = SiteRoot + "/eletter/LetterView.aspx?l=" + letter.LetterInfoGuid.ToString() + "&letter=" + letter.LetterGuid.ToString(); } letterSender.QueueTask(); string redirectUrl = SiteRoot + "/eletter/SendProgress.aspx?l=" + letterInfoGuid.ToString() + "&letter=" + letterGuid.ToString() + "&t=" + letterSender.TaskGuid.ToString(); WebTaskManager.StartOrResumeTasks(); WebUtils.SetupRedirect(this, redirectUrl); }
private bool SaveOrderSummary(Order order, List <ShoppingCartItem> cartList) { List <Product> lstProductsInCart = Product.GetByShoppingCart(siteSettings.SiteId, CartHelper.GetCartSessionGuid(siteSettings.SiteId)); List <CustomField> customFields = new List <CustomField>(); List <ProductProperty> productProperties = new List <ProductProperty>(); if (ProductConfiguration.EnableShoppingCartAttributes && ProductConfiguration.EnableAttributesPriceAdjustment) { List <int> lstProductIds = lstProductsInCart.Select(x => x.ProductId).Distinct().ToList(); productProperties = ProductProperty.GetPropertiesByProducts(lstProductIds); if (productProperties.Count > 0) { var customFieldIds = productProperties.Select(x => x.CustomFieldId).Distinct().ToList(); customFields = CustomField.GetByOption(CustomField.GetActiveByFields(siteSettings.SiteId, Product.FeatureGuid, customFieldIds), CustomFieldOptions.EnableShoppingCart); } } //List<CouponAppliedToItem> lstAppliedItems = new List<CouponAppliedToItem>(); //Coupon coupon = null; //if (CartHelper.CouponCodeInput.Length > 0) // lstAppliedItems = CartHelper.GetAppliedItems(siteSettings.SiteId, cartList, lstProductsInCart, out coupon); decimal totalDiscount = decimal.Zero; List <OrderItem> lstOrderItem = new List <OrderItem>(); foreach (ShoppingCartItem itm in cartList) { Product product = ProductHelper.GetProductFromList(lstProductsInCart, itm.ProductId); if (product != null) { decimal discount = decimal.Zero; decimal price = ProductHelper.GetPrice(product); //if (lstAppliedItems.Count > 0) //{ // CouponAppliedToItem appliedToItem = CouponAppliedToItem.FindFromList(lstAppliedItems, product.ZoneId, (int)CouponAppliedType.ToCategories); // if (appliedToItem == null) // appliedToItem = CouponAppliedToItem.FindFromList(lstAppliedItems, product.ProductId, (int)CouponAppliedType.ToProducts); // if (appliedToItem != null) // { // int totalRemain = 0; // if (coupon.MaximumQtyDiscount > 0) // { // int totalQty = OrderItem.GetTotalItemsByCoupon(product.ProductId, coupon.CouponCode); // totalRemain = coupon.MaximumQtyDiscount - totalQty; // if (totalRemain <= 0) // totalRemain = -1; // } // if (totalRemain >= 0) // { // int qtyApplied = Math.Min(coupon.DiscountQtyStep, itm.Quantity); // if (totalRemain > 0) // qtyApplied = Math.Min(qtyApplied, totalRemain); // if (appliedToItem.Discount > 0) // { // if (appliedToItem.UsePercentage) // discount = (appliedToItem.Discount * product.Price * qtyApplied) / 100; // else // discount = appliedToItem.Discount * qtyApplied; // } // else // { // if (coupon.DiscountType == (int)CouponDiscountType.PercentagePerProduct) // discount = (coupon.Discount * product.Price * qtyApplied) / 100; // else // discount = coupon.Discount * qtyApplied; // } // totalDiscount += discount; // } // } //} if (!string.IsNullOrEmpty(itm.AttributesXml)) { var attributes = ProductAttributeParser.ParseProductAttributeMappings(customFields, itm.AttributesXml); if (attributes.Count > 0) { foreach (var a in attributes) { var values = ProductAttributeParser.ParseValues(itm.AttributesXml, a.CustomFieldId); if (values.Count > 0) { productProperties.ForEach(property => { if (property.ProductId == product.ProductId && property.CustomFieldId == a.CustomFieldId && values.Contains(property.CustomFieldOptionId)) { price += property.OverriddenPrice; } }); } } } } OrderItem orderItem = new OrderItem(); orderItem.OrderId = order.OrderId; orderItem.Price = price; orderItem.DiscountAmount = discount; orderItem.ProductId = itm.ProductId; orderItem.Quantity = itm.Quantity; orderItem.AttributesXml = itm.AttributesXml; orderItem.AttributeDescription = itm.CreatedFromIP; totalDiscount += discount; orderItem.Save(); lstOrderItem.Add(orderItem); } ShoppingCartItem.Delete(itm.Guid); } decimal shippingPrice = decimal.Zero; if (order.ShippingMethod > 0) { decimal orderSubTotal = cartList.GetSubTotal(lstProductsInCart); decimal orderWeight = cartList.GetTotalWeights(lstProductsInCart); int productTotalQty = cartList.GetTotalProducts(); string geoZoneGuids = ProductHelper.GetShippingGeoZoneGuidsByOrderSession(order); shippingPrice = ProductHelper.GetShippingPrice(order.ShippingMethod, orderSubTotal, orderWeight, productTotalQty, geoZoneGuids); } decimal subTotal = cartList.GetSubTotal(lstProductsInCart); //order.UserPoint = 0; //order.UserPointDiscount = 0; //int point = 0; //string currentPoint = GetPostValue("hdfCurrentPoint", "0"); //int.TryParse(currentPoint, out point); //if (point >= 0 && Request.IsAuthenticated) //{ // SiteUser siteUser = SiteUtils.GetCurrentSiteUser(); // if (siteUser != null && siteUser.UserId > 0 && point <= siteUser.TotalPosts) // { // order.UserPoint = point; // order.UserPointDiscount = ProductHelper.GetDiscountByPoint(point); // int bonusPoint = Convert.ToInt32(Math.Round(subTotal / 1000)); // SiteUserEx.UpdateUserPoints(siteUser.UserGuid, (siteUser.TotalPosts - point) + bonusPoint); // } //} decimal total = CartHelper.GetCartTotal(subTotal: subTotal, shippingTotal: shippingPrice, pointDiscount: order.UserPointDiscount); order.OrderDiscount = totalDiscount; order.OrderSubtotal = subTotal; order.OrderShipping = shippingPrice; order.OrderTotal = total; //if (lstAppliedItems.Count > 0 && coupon != null) //{ // order.CouponCode = coupon.CouponCode; // var history = new CouponUsageHistory(); // history.OrderId = order.OrderId; // history.CouponId = coupon.CouponId; // history.Save(); //} order.Save(); string billingProvinceName = string.Empty; string billingDistrictName = string.Empty; string shippingProvinceName = string.Empty; string shippingDistrictName = string.Empty; if (order.BillingProvinceGuid != Guid.Empty) { var province = new GeoZone(order.BillingProvinceGuid); if (province != null && province.Guid != Guid.Empty) { billingProvinceName = province.Name; } } if (order.BillingDistrictGuid != Guid.Empty) { var province = new GeoZone(order.BillingDistrictGuid); if (province != null && province.Guid != Guid.Empty) { billingDistrictName = province.Name; } } if (order.ShippingProvinceGuid != Guid.Empty) { var province = new GeoZone(order.ShippingProvinceGuid); if (province != null && province.Guid != Guid.Empty) { shippingProvinceName = province.Name; } } if (order.ShippingDistrictGuid != Guid.Empty) { var province = new GeoZone(order.ShippingDistrictGuid); if (province != null && province.Guid != Guid.Empty) { shippingDistrictName = province.Name; } } string toEmail = order.BillingEmail.Trim(); if ( order.ShippingEmail.Length > 0 && !string.Equals(toEmail, order.ShippingEmail, StringComparison.CurrentCultureIgnoreCase) ) { toEmail += "," + order.ShippingEmail; } //ProductHelper.SendOrderPlacedNotification(siteSettings, order, lstProductsInCart, lstOrderItem, "OrderPlacedCustomerNotification", billingProvinceName, billingDistrictName, shippingProvinceName, shippingDistrictName, toEmail); ProductHelper.SendOrderPlacedNotification(siteSettings, order, lstProductsInCart, lstOrderItem, "OrderPlacedStoreOwnerNotification", billingProvinceName, billingDistrictName, shippingProvinceName, shippingDistrictName); WebTaskManager.StartOrResumeTasks(); return(true); }
public static void SendApprovalRequestNotification( SmtpSettings smtpSettings, SiteSettings siteSettings, int workflowId, SiteUser submittingUser, News draftNews ) { if (!draftNews.StateId.HasValue) { return; } WorkflowState workflowState = WorkflowHelper.GetWorkflowState(workflowId, draftNews.StateId.Value); if (workflowState == null || workflowState.StateId == -1) { return; } if (workflowState.ReviewRoles.Length == 0 || workflowState.NotifyTemplate.Length == 0) //"ApprovalRequestNotification" { return; } string approvalRoles = workflowState.ReviewRoles; gbSiteMapNode gbNode = SiteUtils.GetSiteMapNodeByZoneId(draftNews.ZoneID); if (gbNode != null) { List <string> authorizedRoles = gbNode.AuthorizedRoles.SplitOnCharAndTrim(';'); List <string> reviewRoles = workflowState.ReviewRoles.SplitOnCharAndTrim(';'); if (authorizedRoles.Count > 0 && reviewRoles.Count > 0) { approvalRoles = string.Empty; foreach (string reviewRole in reviewRoles) { foreach (string role in authorizedRoles) { if (reviewRole.ToLower() == role.ToLower()) { approvalRoles += reviewRole + ";"; } } } } } List <string> emailAddresses = SiteUser.GetEmailAddresses(siteSettings.SiteId, approvalRoles); int queuedMessageCount = 0; EmailTemplate template = EmailTemplate.Get(siteSettings.SiteId, workflowState.NotifyTemplate); string subject = template.Subject.Replace("{SiteName}", siteSettings.SiteName); string messageTemplate = template.HtmlBody; List <string> emailTo = (template.ToAddresses.Length > 0 ? ";" + template.ToAddresses : "").SplitOnCharAndTrim(';'); string emailToAddress = string.Empty; foreach (string email in emailAddresses) { if (WebConfigSettings.EmailAddressesToExcludeFromAdminNotifications.IndexOf(email, StringComparison.InvariantCultureIgnoreCase) > -1) { continue; } if (!Email.IsValidEmailAddressSyntax(email)) { continue; } if (!emailToAddress.Contains(email + ";")) { emailToAddress += email + ";"; } } foreach (string email in emailTo) { if (WebConfigSettings.EmailAddressesToExcludeFromAdminNotifications.IndexOf(email, StringComparison.InvariantCultureIgnoreCase) > -1) { continue; } if (!Email.IsValidEmailAddressSyntax(email)) { continue; } if (!emailToAddress.Contains(email + ";")) { emailToAddress += email + ";"; } } string replyEmail = submittingUser.Email; if (template.ReplyToAddress.Length > 0) { replyEmail += ";" + template.ReplyToAddress; } string fromEmailAlias = (template.FromName.Length > 0 ? template.FromName : siteSettings.DefaultFromEmailAlias); StringBuilder message = new StringBuilder(); message.Append(messageTemplate); message.Replace("{Title}", draftNews.Title); message.Replace("{SubmittedDate}", DateTimeHelper.GetLocalTimeString(draftNews.ApprovedUtc, SiteUtils.GetUserTimeZone(), SiteUtils.GetUserTimeOffset())); message.Replace("{SubmittedBy}", submittingUser.Name); message.Replace("{ContentUrl}", NewsHelper.FormatNewsUrl(draftNews.Url, draftNews.NewsID, draftNews.ZoneID)); EmailMessageTask messageTask = new EmailMessageTask(smtpSettings); messageTask.SiteGuid = siteSettings.SiteGuid; messageTask.EmailFrom = siteSettings.DefaultEmailFromAddress; messageTask.EmailFromAlias = fromEmailAlias; messageTask.EmailReplyTo = replyEmail; messageTask.EmailTo = emailToAddress; messageTask.EmailCc = template.CcAddresses; messageTask.EmailBcc = template.BccAddresses; messageTask.UseHtml = true; messageTask.Subject = subject; messageTask.HtmlBody = message.ToString(); messageTask.QueueTask(); queuedMessageCount += 1; //Email.Send( // smtpSettings, // siteSettings.DefaultEmailFromAddress, // siteSettings.DefaultFromEmailAlias, // submittingUser.Email, // email, // string.Empty, // string.Empty, // messageSubject, // message.ToString(), // false, // Email.PriorityNormal); WebTaskManager.StartOrResumeTasks(); }
private void DoSubscribe(LetterInfo letter, string email) { LetterSubscriber s = subscriptions.Fetch(siteSettings.SiteGuid, letter.LetterInfoGuid, email); bool needToSendVerification = false; if (s == null) { s = new LetterSubscriber(); s.SiteGuid = siteSettings.SiteGuid; s.EmailAddress = email; s.LetterInfoGuid = letter.LetterInfoGuid; if (showFormatOptions) { s.UseHtml = rbHtmlFormat.Checked; } else { s.UseHtml = htmlIsDefault; } if ((currentUser != null) && (string.Equals(currentUser.Email, email, StringComparison.InvariantCultureIgnoreCase))) { s.UserGuid = currentUser.UserGuid; s.IsVerified = true; } else { // user is not authenticated but may still exist // attach userguid but don't flag as verified // because we don't know that the user who submited the form is the account owner SiteUser siteUser = SiteUser.GetByEmail(siteSettings, email); if (siteUser != null) { s.UserGuid = siteUser.UserGuid; } } s.IpAddress = SiteUtils.GetIP4Address(); subscriptions.Save(s); LetterInfo.UpdateSubscriberCount(s.LetterInfoGuid); if (!s.IsVerified) { needToSendVerification = true; } } else { // we found an existing subscription if (!s.IsVerified) { // if the current authenticated user has the same email mark it as verified if ((currentUser != null) && (string.Equals(currentUser.Email, email, StringComparison.InvariantCultureIgnoreCase))) { s.UserGuid = currentUser.UserGuid; if (showFormatOptions) { s.UseHtml = rbHtmlFormat.Checked; } subscriptions.Save(s); subscriptions.Verify(s.SubscribeGuid, true, Guid.Empty); } else if (s.BeginUtc < DateTime.UtcNow.AddDays(-WebConfigSettings.NewsletterReVerifcationAfterDays)) { // if the user never verifed before and its been at least x days go ahead and send another chance to verify needToSendVerification = true; // TODO: maybe we should log this in case some spam script is using the same email over and over // or maybe we should add a verification sent count on subscription } } } if (needToSendVerification) { string verificationTemplate = ResourceHelper.GetMessageTemplate(SiteUtils.GetDefaultCulture(), "NewsletterVerificationEmailMessage.config"); string confirmLink = siteRoot + "/eletter/Confirm.aspx?s=" + s.SubscribeGuid.ToString(); string messageBody = verificationTemplate.Replace("{NewsletterName}", letter.Title).Replace("{ConfirmationLink}", confirmLink).Replace("{SiteLink}", siteRoot); string subject = string.Format(CultureInfo.InvariantCulture, Resource.NewsletterVerifySubjectFormat, letter.Title); EmailMessageTask messageTask = new EmailMessageTask(SiteUtils.GetSmtpSettings()); messageTask.SiteGuid = siteSettings.SiteGuid; if (letter.FromAddress.Length > 0) { messageTask.EmailFrom = letter.FromAddress; } else { messageTask.EmailFrom = siteSettings.DefaultEmailFromAddress; } messageTask.EmailTo = email; messageTask.Subject = subject; messageTask.TextBody = messageBody; messageTask.QueueTask(); WebTaskManager.StartOrResumeTasks(); } }
private void btnSend_Click(object sender, EventArgs e) { bool isValid = true; reqEmail.Validate(); if (!reqEmail.IsValid) { isValid = false; } regexEmail.Validate(); if (!regexEmail.IsValid) { isValid = false; } reqToEmail.Validate(); if (!reqToEmail.IsValid) { isValid = false; } regexToEmail.Validate(); if (!regexToEmail.IsValid) { isValid = false; } if (isValid) { //string messageTemplate = MessageTemplate.GetMessage("EmailSubjectNotification"); //string url = WebUtils.ParseStringFromQueryString("u", string.Empty); //StringBuilder message = new StringBuilder(); //message.Append(messageTemplate); //message.Replace("{SiteName}", siteSettings.SiteName); //message.Replace("{Name}", txtName.Text); //message.Replace("{Email}", txtEmail.Text); //message.Replace("{Link}", url); //message.Replace("{Message}", txtMessage.Text); //string fromAddress = siteSettings.DefaultEmailFromAddress; EmailTemplate template = EmailTemplate.Get(siteSettings.SiteId, "EmailSubjectNotification", WorkingCulture.LanguageId); string subjectEmail = template.Subject.Replace("{SiteName}", siteSettings.SiteName).Replace("{Subject}", txtSubject.Text.Trim()); string url = WebUtils.ParseStringFromQueryString("u", string.Empty); StringBuilder message = new StringBuilder(); message.Append(template.HtmlBody); message.Replace("{SiteName}", siteSettings.SiteName); message.Replace("{Name}", txtName.Text); message.Replace("{Email}", txtEmail.Text); message.Replace("{Link}", url); message.Replace("{Message}", txtMessage.Text); string fromAddress = siteSettings.DefaultEmailFromAddress; string fromAlias = template.FromName; if (fromAlias.Length == 0) { fromAlias = siteSettings.DefaultFromEmailAlias; } string emailTo = (template.ToAddresses.Length > 0 ? ";" + template.ToAddresses : ""); string emailCc = template.CcAddresses; string emailBcc = template.BccAddresses; string emailReplyTo = (template.ReplyToAddress.Length > 0 ? ";" + template.ReplyToAddress : ""); SmtpSettings smtpSettings = SiteUtils.GetSmtpSettings(); try { //Email.SendEmail( // smtpSettings, // fromAddress, // txtEmail.Text, // txtToEmail.Text, // string.Empty, // string.Empty, // "[" + siteSettings.SiteName + "]" + (this.txtSubject.Text.Trim() != "" ? (": " + this.txtSubject.Text.Trim()) : ""), // message.ToString(), // true, // "Normal"); EmailMessageTask messageTask = new EmailMessageTask(smtpSettings); messageTask.SiteGuid = siteSettings.SiteGuid; messageTask.EmailFrom = fromAddress; messageTask.EmailFromAlias = fromAlias; messageTask.EmailReplyTo = txtEmail.Text.Trim() + emailReplyTo; messageTask.EmailTo = txtToEmail.Text.Trim() + emailTo; messageTask.EmailCc = emailCc; messageTask.EmailBcc = emailBcc; messageTask.UseHtml = true; messageTask.Subject = subjectEmail; messageTask.HtmlBody = message.ToString(); messageTask.QueueTask(); WebTaskManager.StartOrResumeTasks(); } catch (Exception ex) { log.Error("Error sending email from address was " + fromAddress + " to address was " + txtToEmail.Text, ex); } this.lblMessage.Text = MessageTemplate.GetMessage("EmailSubjectThankYouMessage", NewsResources.EmailSubjectThankYouLabel); this.pnlSend.Visible = false; SetupScript(); } }
void btnSendToList_Click(object sender, EventArgs e) { SaveLetter(); if (!LetterIsValidForSending()) { return; } if (letter.SendCompleteUtc > DateTime.MinValue) { return; } // TODO: implement approval process letter.ApprovedBy = currentUser.UserGuid; letter.IsApproved = true; string baseUrl = WebUtils.GetHostRoot(); if (WebConfigSettings.UseFoldersInsteadOfHostnamesForMultipleSites) { // in folder based sites the relative urls in the editor will already have the folder name // so we want to use just the raw site root not the navigation root baseUrl = WebUtils.GetSiteRoot(); } string content = SiteUtils.ChangeRelativeUrlsToFullyQuailifiedUrls(baseUrl, ImageSiteRoot, letter.HtmlBody); letter.HtmlBody = content; SaveLetter(); letter.TrackSendClicked(); LetterSendTask letterSender = new LetterSendTask(); letterSender.SiteGuid = siteSettings.SiteGuid; letterSender.QueuedBy = currentUser.UserGuid; letterSender.LetterGuid = letter.LetterGuid; letterSender.UnsubscribeLinkText = Resource.NewsletterUnsubscribeLink; letterSender.UnsubscribeUrl = SiteRoot + "/eletter/Unsubscribe.aspx"; letterSender.NotificationFromEmail = siteSettings.DefaultEmailFromAddress; letterSender.NotifyOnCompletion = true; letterSender.NotificationToEmail = currentUser.Email; SmtpSettings smtpSettings = SiteUtils.GetSmtpSettings(); letterSender.User = smtpSettings.User; letterSender.Password = smtpSettings.Password; letterSender.Server = smtpSettings.Server; letterSender.Port = smtpSettings.Port; letterSender.RequiresAuthentication = smtpSettings.RequiresAuthentication; letterSender.UseSsl = smtpSettings.UseSsl; letterSender.PreferredEncoding = smtpSettings.PreferredEncoding; //localizing the task name can cause deserialization errors //letterSender.TaskName = string.Format(CultureInfo.InvariantCulture, // Resource.NewsletterTaskNameFormatString, letterInfo.Title); //letterSender.NotificationSubject = string.Format(CultureInfo.InvariantCulture, // Resource.TaskQueueCompletedTaskNotificationFormatString, letterSender.TaskName); //letterSender.StatusCompleteMessage = Resource.NewsletterStatusCompleteMessage; //letterSender.StatusQueuedMessage = Resource.NewsletterStatusQueuedMessage; //letterSender.StatusStartedMessage = Resource.NewsletterStatusStartedMessage; //letterSender.StatusRunningMessage = Resource.NewsletterStatusRunningMessageFormatString; //letterSender.TaskCompleteMessage = string.Format(CultureInfo.InvariantCulture, // Resource.TaskQueueCompletedTaskNotificationFormatString, letterSender.TaskName); letterSender.QueueTask(); string redirectUrl = SiteRoot + "/eletter/SendProgress.aspx?l=" + letterInfoGuid.ToString() + "&letter=" + letterGuid.ToString() + "&t=" + letterSender.TaskGuid.ToString(); WebTaskManager.StartOrResumeTasks(); WebUtils.SetupRedirect(this, redirectUrl); }