Hi Joe
Since there are planned enhancements on its way it will be difficult to keep things aligned.
Main thing i was missing for my clients is the ability to import a textfile with email addresses and assign them to one or more newsletters.
Created a simple pageI've copied the eLetter module and all pages and put everything in a new project.
Currently there is an ASPX page with a file upload for the importer and the code behind which is pretty simple.
i like simple to will just add the code here (watch for changed namespace because of project copy)
ASPX page
<%@ Page Title="" Language="C#" MasterPageFile="~/App_MasterPages/layout.Master" AutoEventWireup="true" CodeBehind="LetterImport.aspx.cs" Inherits="PraveMarketing.UI.LetterImport" %>
<asp:Content ContentPlaceHolderID="leftContent" ID="MPLeftPane" runat="server" />
<asp:Content ContentPlaceHolderID="mainContent" ID="MPContent" runat="server">
<div class="breadcrumbs">
<span id="spnAdmin" runat="server"><asp:HyperLink ID="lnkLetterAdmin" runat="server" CssClass="unselectedcrumb" /> ></span>
<asp:HyperLink ID="lnkThisPage" runat="server" CssClass="selectedcrumb" />
</div>
<asp:Repeater ID="rptLetters" runat="server">
<HeaderTemplate><ul class='simplelist newsletterlist'></HeaderTemplate>
<ItemTemplate>
<li>
<input type="checkbox"
id='chk<%# DataBinder.Eval(Container.DataItem,"LetterInfoGuid").ToString() %>' checked="checked"
title='<%# DataBinder.Eval(Container.DataItem,"Title") %>' name='chk<%# DataBinder.Eval(Container.DataItem,"LetterInfoGuid").ToString() %>' />
<label for='chk<%# DataBinder.Eval(Container.DataItem,"LetterInfoGuid").ToString() %>'><%# DataBinder.Eval(Container.DataItem,"Title") %></label>
</li>
</ItemTemplate>
<FooterTemplate></ul></FooterTemplate>
</asp:Repeater>
<div>
<asp:FileUpload ID="FileUpload1" runat="server" /><br />
<portal:mojoButton ID="BtnUpload" runat="server"
onclick="btnUploadAndImport_Click" />
</div>
</asp:Content>
<asp:Content ContentPlaceHolderID="rightContent" ID="MPRightPane" runat="server" />
<asp:Content ContentPlaceHolderID="pageEditContent" ID="MPPageEdit" runat="server" />
CODE BEHIND
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Web.UI;
using System.Web.UI.WebControls;
using mojoPortal.Web.Framework;
using mojoPortal.Web.Editor;
using mojoPortal.Business;
using mojoPortal.Business.WebHelpers;
using mojoPortal.Net;
using Resources;
using mojoPortal.Web;
using System.IO;
using System.Text;
// resource
// lnkLetterImportLink Import CSV file
namespace PraveMarketing.UI
{
public partial class LetterImport : NonCmsBasePage
{
private SiteSettings siteSettings = null;
private SubscriberRepository subscriptions = new SubscriberRepository();
private List<LetterInfo> siteAvailableSubscriptions = null;
protected string siteRoot = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
BtnUpload.Text = Resource.BtnUploadText;
BindList();
}
private void BindList()
{
siteSettings = CacheHelper.GetCurrentSiteSettings();
siteRoot = SiteUtils.GetNavigationSiteRoot();
siteAvailableSubscriptions = NewsletterHelper.GetAvailableNewslettersForCurrentUser(siteSettings.SiteGuid);
if (siteSettings == null) { return; }
if (siteAvailableSubscriptions == null) { return; }
rptLetters.DataSource = siteAvailableSubscriptions;
rptLetters.DataBind();
if (rptLetters.Items.Count == 0) { this.Visible = false; }
}
protected void btnUploadAndImport_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string dataFolder = Server.MapPath(siteSettings.DataFolder);
string fileName = "import.txt";
string fullCleanedFileNameWithPath = dataFolder + fileName;
FileUpload1.SaveAs(fullCleanedFileNameWithPath);
//read the file into a list of String and Subscribe them
string[] emails = File.ReadAllLines(fullCleanedFileNameWithPath);
foreach (string emailaddress in emails)
{ DoSubscribe(emailaddress); }
}
}
private void DoSubscribe(string emailAddressToSubscribe)
{
foreach (LetterInfo available in siteAvailableSubscriptions)
{
string controlID = "chk" + available.LetterInfoGuid.ToString();
if (Request.Params.Get(controlID) != null) //only found if checked
{
DoSubscribe(available, emailAddressToSubscribe);
}
}
}
private void DoSubscribe(LetterInfo letter, string email)
{
LetterSubscriber s = subscriptions.Fetch(siteSettings.SiteGuid, letter.LetterInfoGuid, email);
if (s == null)
{
s = new LetterSubscriber();
s.SiteGuid = siteSettings.SiteGuid;
s.EmailAddress = email;
s.LetterInfoGuid = letter.LetterInfoGuid;
s.UseHtml = true;
s.UserGuid = new Guid();
s.IsVerified = true;
s.IpAddress = SiteUtils.GetIP4Address();
SiteUser siteUser = SiteUser.GetByEmail(siteSettings, email);
//if user exist use userguid else guid.empte
if (siteUser != null) { s.UserGuid = siteUser.UserGuid; }
subscriptions.Save(s);
LetterInfo.UpdateSubscriberCount(s.LetterInfoGuid);
}
}
}
}
RESOURCE ENHANCEMENT
BtnUploadText Upload txt file
You may use this in your next version.
My next step is to implement a detailed analysis so we can see who has received the eletter and who has read it using a simple handler with a 1px image added to the html message
peter