+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Confirmation email for Newsletter signup

Confirmation email for Newsletter signup

4 posts, 0 answered
  1. Geremy Ferguson
    Geremy Ferguson avatar
    6 posts
    Registered:
    29 Jul 2009
    06 Nov 2009
    Link to this post
    Is there any built-in way to send a confirmation email and require activation from the recipient when signing up for a newsletter?  And if not, has anyone created anything similiar to this?

    -chad
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    09 Nov 2009
    Link to this post
    Hello Geremy Ferguson,

    It is possible although there is no built in functionality. Actually you can initially store all users in a new group called - "NotApproved". You can extend Subscription form control and send a confirmation email. On a custom page you will have another control that will verify the user. If an user confirm his/hers subscription you will move it to another group called - verified.

    Here is a sample code implementation that you can use even for a creating a completely new subscription form

    public void Page_Load(object sender, EventArgs e)
    {
        Button sbutton = (Button)emailhldr.FindControl("CustomSBSCR");
       sbutton.Click += new EventHandler(sbutton_Click);
    }
     
    void sbutton_Click(object sender, EventArgs e)
    {
        Telerik.Notifications.Newsletters.DataManager newsletterManager = new Telerik.Notifications.Newsletters.DataManager();
        string subscriberEmail = string.Empty;
        TextBox emailtb = (TextBox)emailhldr.FindControl("sf1_email");
        if (emailtb != null)
        {
            subscriberEmail = emailtb.Text.ToLower().Trim();
            Telerik.Newsletters.ISubscriber subscriber = newsletterManager.GetSubscriber(subscriberEmail);
            if (subscriber == null)
            {
                subscriber = newsletterManager.CreateSubscriber(subscriberEmail);
                newsletterManager.SaveSubscriber(subscriber);
                CreateGroupRelations(subscriberEmail);
                // EXPOSE ALL HARDCODED VALUES AS PUBLIC PROPERTIES
                System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage("yourmailhere@domain.com", subscriberEmail);
                message.Body = "You need to confirm your subscription for domain.com. Please use this link" +
                    string.Concat("http://localhost:2889/emptyproject/mailconfirm.aspx", "?mail=", subscriber.SubscriberId);
                System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
                client.Send(message);
     
            }
        }
    }
     
    private void CreateGroupRelations(string subscriberEmail)
    {
        Telerik.Notifications.Newsletters.DataManager newsletterManager1 = new Telerik.Notifications.Newsletters.DataManager();
        Telerik.Newsletters.IGroupSubscriber gSub = null;
        Telerik.Newsletters.ISubscriber subscriber = newsletterManager1.GetSubscriber(subscriberEmail);
        //THE GUID OF OUR GROUP.
        Guid groupId = new Guid("DB851AC3-C951-4022-A508-A70FADC9EBF4");
            if (newsletterManager1.GetGroup(groupId) != null)
                if (newsletterManager1.GetGroupSubscriberRelation(groupId, subscriber.SubscriberId) == null)
                {
                    gSub = newsletterManager1.CreateGroupSubscriberRelation(
                       groupId, subscriber.SubscriberId);
                    newsletterManager1.SaveGroupSubscribers(gSub);
     
                }
    }

    Now you need to have confirm subscription control that creates new group relation and moves our user to Approved users group.

    public partial class CustomControls_ConfirmEmailSubscription : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string key = Request.QueryString.AllKeys[0];
            if (key.Equals("mail"))
            {
                Guid val =  new Guid(Request.QueryString[0].ToString());
                if (val !=null)
                {
                    DataManager manager = new DataManager();
                    ISubscriber subscriber = manager.GetSubscriber(val);
     
                    // CREATE SUBSCRIBER GROUP RELATION FOR MOVING THIS USER TO APPROVED ROLE
                }
            }
     
        }
    }


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Marcel S
    Marcel S avatar
    15 posts
    Registered:
    19 Nov 2009
    29 Apr 2011
    Link to this post
    Hello Ivan,

    What do you do if you have two newsletters and thereby four groups? You need to have two similar unsubscription links, but in the newsletter mail form you can only put the standard unsubscribe link. Is there a way to change/manipulate that link? Or is it possible to add a custom BB-Code like that?

    Yours,
    Marcel
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Apr 2011
    Link to this post
    Hi Marcel S,

    The unsubscribe link cannot be manipulated. Generally when you unsubscribe. The problem is that we delete all relations when you use Unsubscribe form. The problem is that we use DeleteGroupSubscriberRelation ( Guid subscriberId )  and group ID is not passed which will allow us to use another overload

    DeleteGroupSubscriberRelation ( Guid groupId, Guid subscriberId ).

    This is a bug in the newsletter that we have to fix.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

Register for webinar
4 posts, 0 answered