[title sub="Written by Chris Graham"]Composr Tutorial: Running a newsletter[/title]

Composr has an inbuilt e-mail newsletter system which will allow you to send out newsletters to subscribers and your members.

{!newsletter:DOC_NEWSLETTER}

Think carefully about how you wish to mix news, forum announcements or forum news, and newsletters for your site: in particular, you may wish to post more news than you send newsletters, or post to both news and newsletters, because news stays on your site in a permanent archive. You may also wish to prepare and use the same content for news as you do newsletters, so as to present a common message.

[contents]decimal,lower-alpha[/contents]

[title="2"]Basic targeting[/title]

[title="3"]Newsletters vs Memberships[/title]

Newsletter subscription is distinct from membership, in that a subscription is solely tied to an e-mail address, and there is no formal tie between a subscription and a member account, and vice versa. This said, the newsletter system has special support for sending out newsletters to usergroup members (Conversr-only) regardless of whether they have specifically subscribed to a newsletter.

A count will be given, counting all targetable members in the usergroup. Targetable means the following criteria need to be true for the member:
 - validated
 - not banned
 - allows staff e-mails (unless the "Allow members to opt-out of staff e-mails" option is not enabled)
 - has a configured e-mail address
 - has not unsubscribed through the global unsubscribe endpoint at [tt]data/unsubscribe.php[/tt]
It only shows usergroups that have at least one targetable member.

If you only ever e-mail members, it is better to ask them to join target usergroups rather than target newsletters. i.e. You may be best off never asking users to join a newsletter directly.

[title="3"]Multiple newsletters[/title]

You may have multiple newsletters in Composr. This allows you to set different subscription areas, or a way to allow people to subscribe to different traffic levels.

[title="2"]Newsletter signup[/title]

[media width="150" description="Subscribing to the newsletter via the maintenance module" float="right"]data_custom/images/docs/tut_newsletter/newsletter_subscribe.png[/media]
If you've decided to use subscribers then...

You will typically invite people to join the newsletter via the [tt]main_newsletter_signup[/tt] block. They will be assigned a randomised maintenance password.

You can also have people signup directly via the [tt]site:newsletter[/tt] module ("maintenance module", About > Newsletter on the default menus). They will choose their maintenance password.

The newsletter process has a mandatory e-mail confirmation step so as to stop people signing up others to the newsletter, which may be illegal in some jurisdictions and is at least a nuisance. This confirmation e-mail is driven by the [tt]NEWSLETTER_SIGNUP_TEXT[/tt] language string.
The exception is the [tt]main_newsletter_signup[/tt], which has an option to instead send a customised e-mail that does not itself require any click-through.

When a user hits the block and subscribes through it, one of the following situations will happen:
 - A new subscription -- Composr will sign them up and send a confirmation e-mail
 - An existing subscription never confirmed -- Composr will treat this as a refresh to a new subscription, re-sending the confirmation e-mail
 - An existing subscription -- Composr will show an error

The maintenance module is a bit richer:
 - A new subscription -- Composr will sign them up and send a confirmation e-mail
 - An existing subscription never confirmed -- Composr will treat this as a refresh to a new subscription, re-sending the confirmation e-mail (regardless of what password was entered)
 - An existing subscription, with the wrong maintenance password -- Composr will give an error (with an option to re-set the password), unless you are logged in with a privileged account
 - An existing subscription, with the correct maintenance password -- Composr will update the newsletter subscription

The block sets only for a single newsletter while the maintenance module can do for multiple newsletters at once. This difference between block and maintenance page is intentional, as the block is intended only for new signups to a specific newsletter, not for changing existing subscriptions.

[title="3"]Manually unsubscribing a member[/title]

The easiest way is to go to where members signup, and act on their behalf.

To unsubscribe a member from a newsletter:
1) Log in with your administrative account, if you haven't already got an admin login open
2) Go to the [tt]newsletter[/tt] module ([tt]site:newsletter[/tt] page-link, About > Newsletter on the default menus)
3) Enter the e-mail address you wish to unsubscribe. Leave all other fields blank.
4) Click "Join newsletter/Change settings"
This works, even though the maintenance password was left blank, because Composr acknowledges your overriding administrative access.

[title="3"]Blocking recipients (advanced)[/title]

If you wish to create a list of e-mail addresses to never send to, you can do so by making an [tt]uploads/website_specific/newsletter_blocked.csv[/tt] spreadsheet file. Put each e-mail address on its own line. A [abbr="Comma-Separated-Values"]CSV[/abbr] spreadsheet file with a single column is the same thing as a simple text file with one entry per line, so it's really simple to edit, whichever way you wish to work. The filter works behind-the-scenes between you choosing to send out your newsletter, and Composr actually sending it. If you have the filter successfully in place then Composr will confirm this with an "You have a [tt]uploads/website_specific/newsletter_blocked.csv[/tt] spreadsheet file in place, blocking (number of addresses) e-mail addresses from receiving the newsletter." message on the newsletter authoring screen ("Send out issue").
The block list is useful for situations such as:
 - A previous send failed part-way-through for some reason, and you have a list of users you know it did get sent to already.
 - You maintain a manual list of users who have unsubscribed and you are very careful to not send to them, even if someone re-subscribes them.
 - You want to block a list of e-mail addresses you know belong to competitors.
You may add additional columns to the CSV spreadsheet file, which will be ignored. You can use this for keeping notes, for example.

[title="3"]Data and Privacy Protection Laws[/title]
[surround]
[media width="150" description="The interface for globally unsubscribing from all mail" float="right"]data_custom/images/docs/tut_newsletter/mail_unsubscribe.png[/media]
The blocklist CSV mentioned above is usually not, however, a satisfactory mechanism for adhering to local privacy and data protection laws (e.g. CAN-SPAM). These laws typically require that you provide an easy and intuitive way for users to unsubscribe themselves from e-mails. While they usually do not specifically require that the process is automatic, laws often define how many days a site administrator has to comply with a request. Even so, it is recommended that the process is automatic.

Fortunately, Composr offers two built-in mechanisms for this which are both automatic:
 - Newsletters have their own unsubscribe link provided in the e-mail. This allows members to unsubscribe themselves from all newsletters but still allows them to receive other e-mails from the site (e.g. notifications).
 - All mail sent from a Composr site by default (in the MAIL template) includes a link to [tt]data/unsubscribe.php[/tt]. This simplified interface allows users to unsubscribe from [b]all[/b] e-mails sent by your site; think of it as a global blocklist. Also by default, the "List-Unsubscribe target" configuration option will point to this endpoint so that mail clients can provide a one-click "Unsubscribe" button to recipients.
[/surround]

[title="2"]Sending newsletters[/title]

[surround]
[media width="150" description="Sending a new issue" float="right"]data_custom/images/docs/tut_newsletter/newsletter_new.png[/media]
Send a new newsletter issue from:
Admin Zone > Tools > Newsletter > Send fresh newsletter issue

In the form you will need to primarily fill the subject line and body for the newsletter. Newsletters are written in [page="_SEARCH:tut_comcode"]Comcode[/page] and can be edited using the [page="_SEARCH:tut_wysiwyg"]WYSIWYG editor[/page].

You need to choose where to send it to. Usergroups/newsletters with no members (to be precise, no members that can receive e-mails) will not be shown as options.

Before your newsletter is sent, you have an opportunity to preview it, so you can ensure it is correct. Look at your preview carefully, as it is easy to make minor typographical or layout mistakes that would affect the professionalism portrayed in these bulk e-mails. You will also be e-mailed the newsletter during the preview stage so that you can perform the ultimate check.

If you have [page="_SEARCH:tut_configuration"]the system scheduler configured[/page], once you proceed to send the e-mails to individual members will be put in 'drip' queue, and mails will be sent out on a cycle. This works around server limits and avoids overloading the server.

[title="3"]Scheduling[/title]

When composing your newsletter you will be given a choice to send it out at a scheduled time (if you have [page="_SEARCH:tut_configuration"]the system scheduler configured[/page]). This is particularly useful for companies that need to coordinate a marketing plan.
[/surround]

[title="3"]Dual format e-mails (advanced)[/title]

[box="Be wary of WYSIWYG" width="25em" float="right"]
You can use the WYSIWYG editor for making newsletters if you wish, but it is not advisable if "Support plain-text e-mails" is enabled, because plain-text readers will get some really ugly plain-text from it. If you make the newsletter using manual Comcode, the plain-text readers will see the Comcode, which is intrinsically easy to read.
[/box]
If the "Support plain-text e-mails" configuration option (Admin Zone > Setup > Configuration > Messages > Newsletter) is enabled (it's not by default) then newsletters are sent out in a dual format: both text and HTML. Most users will be able to read the HTML variant, as this is now by far the standard for common e-mail messages; however if they have this disabled, or an unusual e-mail client that cannot read HTML mails, then they will see the plain text version, which is based on your original Comcode.

[title="3"]Basic templating[/title]

In order to change the newsletter appearance, to something more pleasing, you may wish to edit the [tt]NEWSLETTER_DEFAULT_FCOMCODE.txt[/tt] template. This is a template that defines the default newsletter, and hence you may fill it with Comcode to surround your actual newsletter text, such as to format your newsletter mails in an attractive manner.

Additionally, the US CAN-SPAM act and the UK-equivalent (and likely many other laws in various countries) require you to include a physical address in your mailings, so you should include this in the template.

You also are likely to want to edit the [tt]MAIL.tpl[/tt] template, which defines how e-mails generally look.

You will almost certainly want to edit these templates within the default theme, because if you are sending newsletters from the Admin Zone almost certainly the default theme will be the active theme when the newsletters are generated.

Information on more advanced templating is provided further down in this tutorial.

[title="4"]Custom mail templates for newsletters (advanced)[/title]

When you send a newsletter you can select a mail template to use. Only templates matching the filename pattern [tt]MAIL*.tpl[/tt] will be shown.
If you want new template options here you must manually create new templates with names like this. They must follow the same basic structure as the default [tt]MAIL.tpl[/tt].

[title="2"]Automatic issues[/title]

[media width="150" description="Choosing and arranging content/categories" float="right"]data_custom/images/docs/tut_newsletter/automatic_2.png[/media]
[media width="150" description="Basic parameters for an automatic issue" float="right"]data_custom/images/docs/tut_newsletter/automatic_1.png[/media]
{!newsletter:DOC_WHATSNEW}

[list="1"]
[*] Access this functionality from:
Admin Zone > Tools > Newsletter > Manage automatic issues
You will find you can add (and edit/delete) automatic issues from here.
[*] This will take you to a new screen to define some basic parameters. You can choose whether this will be a periodic automatic issue or just a one-off automatic issue. Configure as appropriate. Periodic automatic issues require the [page="_SEARCH:tut_configuration"]system scheduler[/page] to be configured. Click "Next" when done.
[*] You will be taken to a form that lets you pick what content to include. This consists of a number of lines referencing content and categories, and you must re-arrange/delete lines as appropriate. For each content type supported, it shows only if there are less than 300 items that would be covered (configurable via the "What's New cut-off point" configuration option). If there are 300 or more, then it considers the content type too common to include and no items are shown. Click "Next" when done.
[*] If you are sending a one-off then in the next step you get the opportunity to edit the newsletter before it is sent, to add additional information or otherwise customise existing information to make your newsletter is appropriate. For periodic automatic issues you can't do this, for obvious reasons. From now on the process is like sending a normal new issue -- you get to choose who to target to, see a preview, and confirm.
[/list]

[title="3"]Making media links link to content (advanced)[/title]

If you want to make any media links within the newsletter point to the content resources rather than to the normal media locations (e.g. full-screen media views), then you can edit the [tt]NEWSLETTER_WHATSNEW_RESOURCE_FCOMCODE.txt[/tt] template as follows:
[code="Comcode"]
[title="3"]{NAME@}[/title]

[surround]{+START,IF_PASSED,IMAGE_URL}[img float="right"]{$THUMBNAIL,{IMAGE_URL},170,,,,,,,1}[/img]{+END}{+START,IF_PASSED,DESCRIPTION}{+START,IF_NON_EMPTY,{DESCRIPTION}}\{$SET,comcode__current_linking_context,{URL}\}{DESCRIPTION}\{$SET,comcode__current_linking_context,\}

{+END}{+END}[url="{!VIEW#}"]{URL@}[/url][/surround]
[/code]
This does make the newsletter code look very messy when edited, however (not to the recipients though).

[title="2"]Creating from news[/title]

In a similar vein to automatic issues, you may create newsletters from news. To do this, just visit the view page for the news that you wish to use and click the appropriate link. You will then be given the choice to refine the newsletter before it is sent.

[title="2"]Customised targeting[/title]

You may export the newsletter subscribers to a spreadsheet file, change it somehow (using whatever strategy you like) and then choose to send out newsletters to your altered copy of the spreadsheet file.

This can be used in many ways, such as:
 - Splitting up the subscribers, to do split testing
 - Manually removing competitors from the list
 - Picking out certain members from the newsletter list based on some kind of characteristic (you might use extra software to correlate this against another database in some way)
 - Migrating the subscriber list to another piece of dedicated newsletter software, or sending it to an expert newsletter design company for targeting

You can also import subscribers from a [abbr="Comma-Separated-Values"]CSV[/abbr] spreadsheet file, or send a newsletter to a CSV spreadsheet file (this is done on the newsletter form). Composr is quite flexible in supporting different layouts of CSV spreadsheet file: it will try and auto-sense which columns are which.

All these features are available under Admin Zone > Tools > Newsletter.

[title="2"]Detailed templating (advanced)[/title]

[title="3"]Parameters[/title]

You have the following template variables available to you to reference in your newsletters:
 - [tt]{TITLE}[/tt], The subject line of the e-mail (and also the equivalent of [tt]{TITLE}[/tt] in the [tt]MAIL.tpl[/tt] template)
 - [tt]{FORENAME}[/tt], The forename (first name) of the subscriber (may be blank if it is not known)
 - [tt]{SURNAME}[/tt], The surname (last name) of the subscriber (may be blank if it is not known)
 - [tt]{NAME}[/tt], The full name of the subscriber (either a combination of forename and surname, the members username, or the [tt]NEWSLETTER_SUBSCRIBER_DEFAULT_NAME[/tt] language string -- depending on what data is available on the reader)
 - [tt]{MEMBER_ID}[/tt], The member ID of the subscriber, or blank if there is no discerned member ID
 - [tt]{EMAIL_ADDRESS}[/tt], The e-mail address of the subscriber
 - [tt]{SEND_ID}[/tt], A special code identifying the subscriber (starts with [tt]m[/tt] if it is a member, or [tt]n[/tt] if it is a newsletter subscriber)
 - [tt]{UNSUB_URL}[/tt], A URL to unsubscribe from (one-click unsubscribe for newsletter recipients, a link to account settings for other recipients). If you are using [tt]unsub_url[/tt] in a Comcode newsletter it is very important not to insert it plainly, as Composr will look at the link for a link caption and incidentally click that link for every user. Instead use a Comcode [tt]url[/tt] tag and hence tell Composr what caption to give the link.

These parameters work both in the body of an individual newsletter and the [tt]NEWSLETTER_DEFAULT_FCOMCODE[/tt] template.

[title="3"]Custom Profile Fields[/title]

If sending newsletters to members (via usergroups), rather than via newsletter signup, you can reference Custom Profile Fields using normal Tempcode. For example, to find field #20 for the recipient, [tt]{$CPF_VALUE,20,{MEMBER_ID}}[/tt].

[title="3"]Full HTML[/title]

Want to take things to the next level with your newsletters? You can create full HTML newsletters.

Creating templated newsletters is best shown by example (this is the newsletter itself, fed into the field when you send the newsletter, or put inside the [tt]NEWSLETTER_DEFAULT_FCOMCODE.txt[/tt] template that prepopulates that field):
[code="HTML"]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset={!charset}" />
<title>{TITLE*}</title>
</head>
<body>
	{$,Try and figure out the best greeting from the data available - we prefer to welcome people by forename but we might not have it}
	<p>Dear {+START,IF_NON_EMPTY,{FORENAME*}}{FORENAME}{+END}{+START,IF_EMPTY,{FORENAME}}{NAME*}{+END},</p>

	{$PARAGRAPH,{$?,{$IS_EMPTY,{CONTENT}},Your text goes here.,{CONTENT}}}

	<hr />

	{+START,IF_NON_EMPTY,{UNSUB_URL}}
		<p style="font-size: 0.8em">You're receiving this newsletter because you subscribed at some point. Not interested anymore? <a href="{UNSUB_URL*}">Unsubscribe</a>.</p>
	{+END}
	{+START,IF_EMPTY,{UNSUB_URL}}
		<p style="font-size: 0.8em">You're receiving this e-mail because you are a member on {$SITE_NAME*}.</p>
	{+END}
</body>
</html>
[/code]

Note how the example includes the [tt]html[/tt] tag, etc -- it is not a snippet, it is a full piece of HTML. This is optional, but if you do write your newsletters like this Composr will be clever enough to bypass wrapping the newsletter in the standard [tt]MAIL.tpl[/tt] template. It will also assume that the body of any new newsletter is in HTML, so Comcode will no longer be supported (but Tempcode will work).

This bit may confuse you: [tt]{+START,IF_NON_EMPTY,{forename}}{forename}{+END}{+START,IF_EMPTY,{forename}}{name}{+END}[/tt]
It is saying "if the forename is available, use the forename, if the forename is not available, use the username".

[title="3"]Processing flow[/title]

Newsletters are processed for each recipient in the following steps:
1) Tempcode evaluated in the newsletter body
2) Parameters bound to the above Tempcode ([tt]{FORENAME}[/tt] etc)
3) Wrapper template applied
4) Parameters bound to the wrapper template
5) If in Comcode format, Comcode is evaluated by Composr's mailer &ndash; otherwise raw-HTML is sent

[title="2"]Bounce filtering (advanced)[/title]

There is a feature for removing newsletter subscribers that bounce e-mails (i.e. dead e-mail accounts). This stops noise coming back when you send out a newsletter, and increases the efficiency of future sends.

Access this from under Admin Zone > Tools > Newsletter > Bounce filter.

The removal process also removes the "allow staff e-mails" setting from members who have a matching e-mail address.

For this tool to work, you must have the PHP IMAP extension on your server.

You should manually move anything sent to your website e-mail address that looks like a bounce e-mail into a new bounces folder, and then run the tool upon that folder:
1) Go to Admin Zone > Tools > Newsletter.
2) Select the "Bounce filter" icon.
3) Enter your server IMAP details.
4) Select your bounces folder (if Composr can see one that matches the word "bounce", it will be auto-selected). Note that if you select a folder with too many e-mail messages in (i.e. something that doesn't just contain bounce e-mails) then Composr could give you an error due to running out of memory

Composr will then show e-mail addresses found within e-mails in the selected folder, where it can find a matching newsletter/member account for an e-mail address. Any e-mail address attached to an e-mail that looks like a bounce e-mail will be auto-ticked (auto-checked). If you are confident the IMAP folder only contained bounces, you can tick (check) the remaining addresses.

If you proceed through, all ticked (checked) e-mails will be removed from the newsletter / have their "allow staff e-mail" member setting disabled.

[title="2"]Newsletter archive[/title]

There is a newsletter archive available (from under Admin Zone > Tools > Newsletter > Newsletter archive), so that you may browse through past newsletters, to make sure you present a consistent image, and generally keep track of what has been sent out in bulk for professional reasons.

[title="2"]Welcome e-mails[/title]

Welcome e-mails allow you to automatically send out e-mails to new members. This is described in the [page="_SEARCH:tut_adv_members"]Advanced Composr member system[/page] tutorial.

[title="2"]See also[/title]

 - [page="_SEARCH:tut_news"]Releasing news & running a Blog[/page]
 - [page="_SEARCH:tut_email"]Understanding and configuring e-mail[/page]
 - [page="_SEARCH:tut_legal"]Legal and social responsibilities[/page]
 - https://www.litmus.com/

{$SET,tutorial_tags,Newsletters,newsletter,novice}{$SET,tutorial_add_date,Aug 2008}{$SET,tutorial_summary,How to send out news bulletins to newsletter subscribers, and to members of your community.}[block]main_tutorial_rating[/block]
