Since the newsletter package makes use of members and member groups as mailing lists we need to set up the members section with member types and groups. In the example below we use a membertype called NewsletterType and a membergroup called NewsletterGroup.

In your solution you'll have to create a new usercontrol, which will be our base for the subscribe macro.
  • Add a reference to the Designit.Umb.Newsletter.Bll.dll (located in your umbraco bin folder)
  • Add a textbox to your usercontrol <asp:TextBox ID="txtEmail" runat="server" /> where the user can input their e-mail address
  • Add a button <asp:Button ID="btnSubscribe" runat="server" Text="Subscribe" onclick="btnSubscribe_Click" />
  • In the code behind we need to add the user to our members if not already a member and also make sure
//Code behind - void btnSubscribe_Click
if(Member.GetMemberFromEmail(txtEmail.Text) == null)
{
  var memberType = MemberType.GetByAlias("NewsletterType");
  Member newMember = Member.MakeNew(txtEmail.Text, txtEmail.Text, memberType, new User(0));
  var password = Membership.GeneratePassword(7, 1);
  newMember.Email = txtEmail.Text;
  newMember.LoginName = txtEmail.Text;
  newMember.Password = password;
  newMember.Save();
}


The Membership.GeneratePassword() is a method located in the System.Web.Security. This is used to fill the demands regarding passwords for members in umbraco. Your password needs o be at atleast 7 digest and contain one none alphabetic value.
To sum up you have now created a member and assosiated it with a type. Had you already created the member simply retrieve the member by the email with the following code:
Member member = Member.GetMemberFromEmail(txtEmail.Text);

You can of course add more fields etc. to members. Look at the umbraco documentation on how to handle members.

We also need to add associate the member with the member group(s).
Designit.Umb.Newsletter.Bll.subscribe sub = new Bll.subscribe();
sub.assignMemberToGroup(member, "NewsletterGroup");
//if you want the user to be added to campaigns not sent out yet, add the following
sub.AddToActiveCampaign(member);

  • Now build the solution, copy the dll file to your umbraco bin folder and the ascx file to your umbraco usercontrols folder
  • Create a macro using the usercontrol
  • Add the macro to a page/template of your choice

You're now ready to start retrieving subscribers.

Last edited Apr 7, 2010 at 10:41 AM by raly76, version 3

Comments

akeilox Sep 17, 2012 at 10:22 AM 
Using Razor to test out the code snippets, I have reference @using Designit.Umb.Newsletter.Bll

then later in the code the line throws error, cant fing subscribe(). Noticed from the Source that this method is defined under UserControl as Subscribe()?

Basically I am wondering whats the different of the 2nd snippet of the code on this page v.s. adding the user to the NewsletterGroup..

Whats does AddToActiveCampaign(member) does that Member.AddGroup(nodeIdofNewsletterGroup) does not?

Many thank in advance.