Page 1 of 1

Email customers?

Posted: Tue Nov 04, 2008 10:06 am
by gio50000
How can I send an email to all of my users?

Thanks,
Gio

Re: Email customers?

Posted: Tue Nov 04, 2008 10:17 am
by gio50000
I created an email list to contact users. Is there a way to add all users at once rather than one at a time?

Gio

Re: Email customers?

Posted: Tue Nov 04, 2008 10:53 am
by mazhar
You have to add the customers one by one to the Email list.

Re: Email customers?

Posted: Tue Nov 04, 2008 10:58 am
by mazhar
Here is the helper code. The following changes will make two buttons available on the ManageUsers page will allow you to add/remove all users from the Email list in one go.

Please take backup of your Admin\Marketing\Email\ManageUsers.aspx and Admin\Marketing\Email\ManageUsers.aspx.cs files before making these changes.

Edit your Admin\Marketing\Email\ManageUsers.aspx file and locate the following line of code

Code: Select all

<asp:ObjectDataSource ID="SearchUsersDs" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="FindUsersByName" TypeName="CommerceBuilder.Users.UserDataSource"
and put the following code just above it so that it should look like as below

Code: Select all

<asp:Button ID="AddAllUsersButton" runat="server" OnClientClick="return confirm('Do you want to add all users to this Email list?');" OnClick="AddAllUsersButton_Click"
                        Text="Add All" />
                    <asp:Button ID="RemoveAllUsersButton" runat="server" OnClick="RemoveAllUsersButton_Click" OnClientClick="return confirm('Do you want to remove all users from this Email list?');"
                        Text="Remove All" /><br />

                            <asp:ObjectDataSource ID="SearchUsersDs" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="FindUsersByName" TypeName="CommerceBuilder.Users.UserDataSource"
Now edit your Admin\Marketing\Email\ManageUsers.aspx.cs file and add following two methods to it

Code: Select all

protected void AddAllUsersButton_Click(object sender, EventArgs e)
    {

        UserCollection users = UserDataSource.FindUsersByName(String.Empty,UserDataSource.NameSearchField.Email);
        foreach (User user in users)
        {
            if(!_EmailList.IsMember(user.UserName))
                _EmailList.AddMember(user.UserName, LocaleHelper.LocalNow, Request.UserHostAddress);
        }
        Response.Redirect(Request.Url.ToString());
    }
    protected void RemoveAllUsersButton_Click(object sender, EventArgs e)
    {
        UserCollection users = UserDataSource.FindUsersByName(String.Empty, UserDataSource.NameSearchField.Email);
        foreach (User user in users)
        {
            if (_EmailList.IsMember(user.UserName))
                _EmailList.RemoveMember(user.UserName);
        }
        Response.Redirect(Request.Url.ToString());
    }

Re: Email customers?

Posted: Tue Nov 04, 2008 12:29 pm
by gio50000
mazhar - the helper code worked perfectly!

Thank you,
Gio

Re: Email customers?

Posted: Tue Nov 04, 2008 12:43 pm
by mazhar
That's great. The option for adding or removing the users in bulk will be very helpful, so I just created an enhancement request for the future version.