You have probably experienced this when you have valid SMTP settings for your Newsletters module and have sent/received the test e-mail that the SMTP settings are valid, however when you go to send your news letter it sends several e-mails and then "freezes." There are three major reasons for this and this KB article will help you deal with them.
The first reason for the newsletter sending to "freeze" is that the SMTP server has been flooded with too many e-mails at the same time. In order to deal with this issue you can just increase the interval for sending e-mails. This way you can set the newsletter manager to send e-mails every N milliseconds. To configure this go to your web.config find the notifications configuration section and edit the sending interval property:
| <notifications defaultProvider="Notifications"> |
| <providers> |
| <clear/> |
| <add name="Notifications" |
| type="Telerik.Notifications.Data.DefaultProvider, Telerik.Notifications.Data" |
| connectionStringName="DefaultConnection" |
| EnableSsl="false" |
| MergedFields="FirstName;LastName" |
| SendingInterval="1000"/> |
| </providers> |
| |
The second and third reasons for the newsletter sending to stall are that your subscribers have entered invalid data for first and last name and e-mails. The first and last names for subscribers must consist of English alpha-numeric characters and the requirement for emails is that they are valid. You can customize newsletter subscription control template and use regular expressions to check the validity of data entered. To do this go to ~/Sitefinity/ControlTemplates/Newsletters/SubscriptionFormTemplate.ascx.
If you are using e-mail only mode for the subscription form you should
add reg ex validator only to textbox with ID sf1_email. If mode with
e-mails and names is used add validators to text controls that are in emailNamehldr placeholder. Bellow are sample regular expression validators which will validate the e-mails and first name:
| <li> |
| <asp:Label ID="Label1" runat="server" Text="Email:" AssociatedControlID="sf2_email"></asp:Label> |
| <asp:TextBox runat="server" ID="sf2_email" CssClass="sf_subscribeTxt" ValidationGroup="subscription"></asp:TextBox> |
| <asp:RequiredFieldValidator ID="emailEmptyValidator2" runat="server" CssClass="sf_emailValidation" |
| ValidationGroup="subscription" ControlToValidate="sf2_email" Display="Dynamic" |
| EnableViewState="False" SetFocusOnError="True"> |
| <strong><asp:Literal ID="Literal7" runat="server" Text="Email cannot be empty!"></asp:Literal></strong> |
| </asp:RequiredFieldValidator> |
| <asp:RegularExpressionValidator ID="emailREValidator2" runat="server" CssClass="sf_emailValidation" |
| ControlToValidate="sf2_email" Display="Dynamic" EnableViewState="false" SetFocusOnError="true" |
| ValidationExpression="^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$" ValidationGroup="subscription"> |
| <strong><asp:Literal ID="literal22" runat="server" Text="Wrong email!"></asp:Literal></strong> |
| </asp:RegularExpressionValidator> |
| </li> |
| <li> |
| <asp:Label ID="Label2" runat="server" AssociatedControlID="sf_firstname" Text="First name:"></asp:Label> |
| <asp:TextBox runat="server" CssClass="sf_subscribeTxt" ID="sf_firstname"></asp:TextBox> |
| <asp:RegularExpressionValidator ID="firstNameValidator" runat="server" CssClass="sf_emailValidation" |
| ControlToValidate="sf_firstname" Display="Dynamic" EnableViewState="false" SetFocusOnError="true" |
| ValidationExpression="^[a-zA-Z0-9]*$" ValidationGroup="subscription"> |
| <strong><asp:Literal ID="literal3" runat="server" Text="First name can contain only Elnglish alphanumeric characters"></asp:Literal></strong> |
| </asp:RegularExpressionValidator> |
| </li> |
| |
Once you have made sure that no faulty data will be entered you can check if the current subscribers have faulty date. For those purposes you can validate against the same regular expressions used above. Bellow is a sample how to check e-mail validity of all newsletters subscribers:
| string emailStrRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" + |
| @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" + |
| @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"; |
| System.Text.RegularExpressions.Regex emailRegex = new System.Text.RegularExpressions.Regex(emailStrRegex); |
| Telerik.Notifications.Newsletters.DataManager newslettersManager = new Telerik.Notifications.Newsletters.DataManager(); |
| foreach (Telerik.Newsletters.ISubscriber subscriber in newslettersManager.GetSubscribers()) |
| { |
| string email = subscriber.Email; |
| if (!emailRegex.IsMatch(email)) |
| { |
| //output fauly email |
| //you can also delete subscriber |
| newslettersManager.DeleteSubscriber(subscriber.SubscriberId); |
| } |
| } |
You can use similar logic for validating subscribers' first and last names.