More in this section

Forums / Developing with Sitefinity / API for sending a confirmation email for a new user.

API for sending a confirmation email for a new user.

5 posts, 0 answered
  1. Alex
    Alex avatar
    4 posts
    Registered:
    26 Jul 2012
    16 Aug 2012
    Link to this post
    How would I go about sending a confirmation email after a new registration without using the existing registration widget? In other words, what's the namespace/api for sending confirmation emails.

    Alternatively, how would I go about adding "sign up to the newsletter" as part of the registration widget? I would idealy like users to be able to decide to sign up for the newsletter as part of the registration process, and not have to fill out extra fields in a separate widget.
  2. Dave
    Dave avatar
    2 posts
    Registered:
    21 Aug 2012
    28 Aug 2012
    Link to this post
    I also need to know how to accomplish this in v5.1
  3. Haithem
    Haithem avatar
    10 posts
    Registered:
    08 Jul 2012
    31 Mar 2013
    Link to this post
    Had anyone got an answer in this regard?.

    Thank you
  4. Rein
    Rein avatar
    22 posts
    Registered:
    07 Oct 2008
    02 Apr 2013
    Link to this post
    If you are using Sitefinity 5.2 or above, then you are probably able to make use of the IEventService and Eventhub. I'm not sure though if you are able to hook in into the user registration process.

    Here's a link to the documentation: http://www.sitefinity.com/documentation/documentationarticles/developers-guide/deep-dive/sitefinity-event-system
  5. Jen Peleva
    Jen Peleva avatar
    568 posts
    Registered:
    10 Nov 2016
    03 Apr 2013
    Link to this post
    Hi guys,

    Here are some suggestions:

    1. How would I go about sending a confirmation email after a new registration without using the existing registration widget? In other words, what's the namespace/api for sending confirmation emails.

    One easy approach would be to replace the default User service with a custom one, that inherits from teh default service. this will allow you to implement the IUsers interface and take advantage of the CreateUser public method. Here's an example of the custom service. Simply add a class file to you project wtih the following code in it: 

    public class UsersServiceCustom:Users, IUsers
    {
        public WcfMembershipUser CreateUser(WcfMembershipUser user, string userId, string provider)
        {
            //you can get  ahold of the created user from the User parameter of the method
            //e.g.
            var myUser = user;
            return base.CreateUser(user, userId, provider);
        }
    }
    Then in the Users.svc file, located under /Services, change the declaration to point to your custom service (UsersServiceCustom is the name of my custom service class):
    <%@ ServiceHost
        Language="C#"
        Debug="false"
        Service="SitefinityWebApp.UsersServiceCustom"
        Factory="Telerik.Sitefinity.Web.Services.WcfHostFactory"
     %>

    Now, having this allows you to execute your own logic whena  user is created and you have access to the user parameter (for example yuo can get the user email from it). Here's a sample code for sending emails with Sitefinity:
    var smtpSettings = Config.Get<SystemConfig>().SmtpSettings;
    MailMessage message = new MailMessage();
    message.From = new MailAddress(smtpSettings.DefaultSenderEmailAddress);
    message.To.Add(new MailAddress("someone@example.com"));
    StringBuilder sb = new StringBuilder();
    sb.AppendFormat("You have been registered");
    message.Subject = "Comments notification";
    message.Body = sb.ToString();
    message.IsBodyHtml = true;
    message.BodyEncoding = Encoding.Unicode;
    message.SubjectEncoding = Encoding.Unicode;
    EmailSender.Get().Send(message);

    2) Alternatively, how would I go about adding "sign up to the newsletter" as part of the registration widget?

     You will find attached a modified Registration form control with a custom template, where I've added a checkBox, and depending on whether this checkBox  is checked, I'm adding the user to a mailing list. All the best,
    Jen Peleva
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
5 posts, 0 answered