Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ASP.NET code samples that generate personalized e-mail content for Commerce Server 2002 ASP.NET site registered users


View products that this article applies to.

Summary

This article contains Microsoft ASP.NET code samples in Microsoft Visual Basic .NET and in Microsoft Visual C#. These ASP.NET code samples generate personalized e-mail content for Microsoft Commerce Server 2002 ASP.NET site registered users.

↑ Back to the top


Introduction

This article contains ASP.NET code samples that generate personalized e-mail content for Commerce Server 2002 ASP.NET site registered users.

The TestEmail.aspx file and the TestEmail.aspx.vb file make up the code sample in Visual Basic .NET. Use this code sample for Commerce Server 2002 solution sites that use Visual Basic .NET.

The MSIBEmail.aspx file and the MSIBEmail.aspx.cs file make up the code sample in Visual C#. Use this code sample for Commerce Server 2002 solution sites that use Visual C#.

Instructions for how to use these code samples in Commerce Server 2002 solution sites are in the "More Information" section. These code samples are provided as-is. You must modify these code samples for custom Commerce Server 2002 ASP.NET sites.

↑ Back to the top


More information

Code sample in Visual Basic .NET

The following code sample is the TestEmail.aspx file.
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="TestEmail.aspx.vb" Inherits="Microsoft.CommerceServer.Site.TestEmail"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
	<HEAD>
		<title>TestEmail</title>
		<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
		<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
		<meta content="JavaScript" name="vs_defaultClientScript">
		<meta content="http://schemas.microsoft.com/intellisense/ie3-2nav3-0" name="vs_targetSchema">
	</HEAD>
	<body MS_POSITIONING="FlowLayout">
		<table style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: #ffff99; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt"
			cellSpacing="0" cellPadding="0" bgColor="#ffff99" border="1">
			<tr>
				<td width="655" valign="top">
					<p class="MsoPlainText"><span style="FONT-FAMILY:Tahoma;

mso-fareast-font-family:'MS Mincho'">

From: E-mail Notifier<o:p></o:p></span></p>
					<p class="MsoPlainText"><span style="FONT-FAMILY:Tahoma;

mso-fareast-font-family:'MS Mincho'">Sent:
<asp:Label id="lblSentDate" runat="server">Sent Date Label</asp:Label><o:p></o:p></span></p>
					<p class="MsoPlainText"><span style="FONT-FAMILY:Tahoma;

mso-fareast-font-family:'MS Mincho'">To:
<asp:Label id="lblName" runat="server">First Name Last Name</asp:Label><o:p></o:p><o:p></o:p></span></p>
					<p class="MsoPlainText"><span style="FONT-FAMILY:Tahoma;

mso-fareast-font-family:'MS Mincho'">Subject: </span><b><span style="FONT-SIZE:12pt;

COLOR:blue;

FONT-FAMILY:Tahoma;

mso-fareast-font-family:'MS Mincho';

mso-bidi-font-size:10.0pt">

New product notice</span></b><span style="mso-fareast-font-family:

'MS Mincho'"><o:p></o:p>
						</span></p>
				</td>
			</tr>
		</table>
		<p class="MsoPlainText"><b><span style="FONT-SIZE:12pt;

COLOR:blue;

mso-fareast-font-family:'MS Mincho';

mso-bidi-font-size:10.0pt"><![if

!supportEmptyParas]><![endif]><o:p></o:p></span></b></p>
		<p class="MsoPlainText"><span style="FONT-FAMILY:Tahoma;

mso-fareast-font-family:'MS Mincho'">Dear 
<asp:Label id="lblFName" runat="server">FirstName</asp:Label>,<o:p></o:p></span></p>
		<p class="MsoPlainText"><span style="FONT-FAMILY:Tahoma;

mso-fareast-font-family:'MS Mincho'"><span style="mso-spacerun: yes"></span>
				<o:p></o:p>
			</span></p>
		<p class="MsoPlainText"><span style="FONT-FAMILY:Tahoma;

mso-fareast-font-family:'MS Mincho'">

<span style="mso-spacerun: yes"></span>We have added some exciting new products to our Web 
site. 
<asp:Label id="lblSiteLink" runat="server">SiteLink</asp:Label>    

      <o:p></o:p>.<o:p></o:p></span></p>
		<p class="MsoNormal" style='mso-layout-grid-align:none'><span style='FONT-SIZE:10pt;

COLOR:navy;

FONT-FAMILY:Arial'><![if !supportEmptyParas]><![endif]><o:p></o:p></span></p>
		<p class="MsoNormal" style='mso-layout-grid-align:none'><span style='FONT-SIZE:10pt;

COLOR:navy;

FONT-FAMILY:Arial'><span style='mso-tab-count:

1'></span>
				<o:p></o:p>
			</span></p>
		<p class="MsoPlainText"><span style="mso-fareast-font-family:

'MS Mincho'">__________________________________________

<o:p></o:p></span></p>
		<p class="MsoPlainText"><i><span style="FONT-SIZE:8pt;

FONT-FAMILY:Verdana;

mso-fareast-font-family:'MS Mincho';

mso-bidi-font-size:10.0pt">TO UNSUBSCRIBE: You

have received this e-mail notifier as a result of your personal 

registration.<BR>To unsubscribe from this e-mail notifier, click

the link below. <o:p></o:p></span></i></p>
		<p class="MsoPlainText"><i><span style="FONT-SIZE:8pt;

FONT-FAMILY:Verdana;

mso-fareast-font-family:'MS Mincho';

mso-bidi-font-size:10.0pt">
					<asp:Label id="lblOptLink" runat="server">opt-out Link</asp:Label>
					<o:p></o:p>
				</span></i></p>
	</body>
</HTML>
The following code sample is the TestEmail.aspx.vb file. The TestEmail.aspx.vb file is the code-behind file for the TestEmail.aspx file.
Imports Microsoft.CommerceServer.Runtime
Imports Microsoft.CommerceServer.Runtime.Profiles
Imports Microsoft.CommerceServer.Runtime.TicketBase


Public Class TestEmail
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents lblFName As System.Web.UI.WebControls.Label
    Protected WithEvents lblSiteLink As System.Web.UI.WebControls.Label
    Protected WithEvents lblSentDate As System.Web.UI.WebControls.Label
    Protected WithEvents lblName As System.Web.UI.WebControls.Label

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer.
        'Do not modify it by using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim FirstName As String
        Dim LastName As String
        Dim MyProfile As Profile
        Dim SentDate As String

        SentDate = Now().ToString()

        CommerceContext.Current.AuthenticationInfo.SetAuthTicket(CommerceContext.Current.UserID, False)

        MyProfile = CommerceContext.Current.UserProfile
        If MyProfile Is Nothing Then
             Response.Write("MyProfile is nothing")
        Else
        FirstName = (MyProfile.Properties("GeneralInfo.first_name").Value).ToString()
        LastName = (MyProfile.Properties("GeneralInfo.last_name").Value).ToString()

        lblSentDate.Text = SentDate
        lblName.Text = FirstName + " " + LastName
        lblFName.Text = FirstName
        'BuildURL can add parameter/value pairs to the URL depending on what you need. Please check doc for QueryStringBuilder.
        lblSiteLink.Text = "<A HREF='" + CommerceContext.Current.QueryStringBuilder.BuildUrl("default.aspx", False) + "'>Come see us today!</A>"
        End If
    End Sub

End Class

Code sample in Visual C#

The following code sample is the MSIBEmail.aspx file.
<%@ Page language="c#" Codebehind="MSIBEmail.aspx.cs" AutoEventWireup="false" Inherits="Microsoft.Solutions.Applications.MSIBEmail" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
	<HEAD>
		<title>MSIBEmail</title>
		<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
		<meta name="CODE_LANGUAGE" Content="C#">
		<meta name="vs_defaultClientScript" content="JavaScript">
		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
	</HEAD>
	<body MS_POSITIONING="FlowLayout">
		<table style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: #ffff99; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt" cellSpacing="0" cellPadding="0" bgColor="#ffff99" border="1">
			<tr>
				<td width="655" valign="top">
					<p class="MsoPlainText"><span style="FONT-FAMILY:Tahoma;

mso-fareast-font-family:'MS Mincho'"> From: E-mail Notifier<o:p></o:p></span></p>
					<p class="MsoPlainText"><span style="FONT-FAMILY:Tahoma;

mso-fareast-font-family:'MS Mincho'">Sent:
							<asp:Label id="lblSentDate" runat="server">Sent Date Label</asp:Label><o:p></o:p></span></p>
					<p class="MsoPlainText"><span style="FONT-FAMILY:Tahoma;

mso-fareast-font-family:'MS Mincho'">To:
							<asp:Label id="lblName" runat="server">First Name Last Name</asp:Label><o:p></o:p><o:p></o:p></span></p>
					<p class="MsoPlainText"><span style="FONT-FAMILY:Tahoma;

mso-fareast-font-family:'MS Mincho'">Subject: </span><b><span style="FONT-SIZE:12pt;

COLOR:blue;

FONT-FAMILY:Tahoma;

mso-fareast-font-family:'MS Mincho';

mso-bidi-font-size:10.0pt">New product notice</span></b><span style="mso-fareast-font-family:

'MS Mincho'"><o:p></o:p>
						</span>
					</p>
				</td>
			</tr>
		</table>
		<p class="MsoPlainText"><b><span style="FONT-SIZE:12pt;

COLOR:blue;

mso-fareast-font-family:'MS Mincho';

mso-bidi-font-size:10.0pt"><![if !supportEmptyParas]><![endif]><o:p></o:p></span></b></p>
		<p class="MsoPlainText"><span style="FONT-FAMILY:Tahoma;

mso-fareast-font-family:'MS Mincho'">Dear
				<asp:Label id="lblFName" runat="server">FirstName</asp:Label>,<o:p></o:p></span></p>
		<p class="MsoPlainText"><span style="FONT-FAMILY:Tahoma;

mso-fareast-font-family:'MS Mincho'"><span style="mso-spacerun: yes"></span>
				<o:p></o:p>
			</span>
		</p>
		<p class="MsoPlainText"><span style="FONT-FAMILY:Tahoma;

mso-fareast-font-family:'MS Mincho'"> <span style="mso-spacerun: yes"></span>We have added some 
				exciting new products to our Web site.
				<asp:Label id="lblSiteLink" runat="server">SiteLink</asp:Label>
				<o:p></o:p>.<o:p></o:p></span></p>
		<p class="MsoNormal" style='mso-layout-grid-align:none'><span style='FONT-SIZE:10pt;

COLOR:navy;

FONT-FAMILY:Arial'><![if !supportEmptyParas]><![endif]><o:p></o:p></span></p>
		<p class="MsoNormal" style='mso-layout-grid-align:none'><span style='FONT-SIZE:10pt;

COLOR:navy;

FONT-FAMILY:Arial'><span style='mso-tab-count:

1'></span>
				<o:p></o:p>
			</span>
		</p>
		<p class="MsoPlainText"><span style="mso-fareast-font-family:

'MS Mincho'">__________________________________________
				<o:p></o:p></span></p>
		<p class="MsoPlainText"><i><span style="FONT-SIZE:8pt;

FONT-FAMILY:Verdana;

mso-fareast-font-family:'MS Mincho';

mso-bidi-font-size:10.0pt">TO UNSUBSCRIBE: You have received this e-mail notifier as a result of 
					your personal registration.<BR>
					To unsubscribe from this e-mail notifier, click the link below.
					<o:p></o:p></span></i></p>
		<p class="MsoPlainText"><i><span style="FONT-SIZE:8pt;

FONT-FAMILY:Verdana;

mso-fareast-font-family:'MS Mincho';

mso-bidi-font-size:10.0pt">
					<asp:Label id="lblOptLink" runat="server">opt-out Link</asp:Label>
					<o:p></o:p>
				</span></i>
		</p>
	</body>
</HTML>
The following code sample is the MSIBEmail.aspx.cs file. The MSIBEmail.aspx.cs file is the code-behind file for the MSIBEmail.aspx file.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.CommerceServer.Runtime;
using Microsoft.CommerceServer.Runtime.Profiles;

namespace Microsoft.Solutions.Applications
{
	/// <summary>
	/// Summary description for MSIBEmail.
	/// </summary>
	public class MSIBEmail : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label lblSentDate;
		protected System.Web.UI.WebControls.Label lblName;
		protected System.Web.UI.WebControls.Label lblFName;
		protected System.Web.UI.WebControls.Label lblSiteLink;
		protected System.Web.UI.WebControls.Label lblOptLink;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			string FirstName;
			string LastName;
			Profile MyProfile;
			string SentDate;

			SentDate = DateTime.Now.ToString();
			CommerceContext.Current.AuthenticationInfo.SetAuthTicket(CommerceContext.Current.UserID, false);

			MyProfile = CommerceContext.Current.UserProfile;

			if (MyProfile!=null)
			{
				FirstName = (MyProfile.Properties["GeneralInfo.first_name"].Value).ToString();
                LastName = (MyProfile.Properties["GeneralInfo.last_name"].Value).ToString();

                lblSentDate.Text = SentDate;
                lblName.Text = FirstName + " " + LastName;
                lblFName.Text = FirstName;
                //BuildURL can add parameter/value pairs to the URL depending on what you need. Please check doc for QueryStringBuilder.
                lblSiteLink.Text = "<A HREF='" + CommerceContext.Current.QueryStringBuilder.BuildUrl("default.aspx", false) + "'>Come see us today!</A>";
                //Opt-out.asp is another page that you must work on if you need this feature.
                lblOptLink.Text = "<A HREF='" + CommerceContext.Current.QueryStringBuilder.BuildUrl("opt-out.aspx", false) + "'>Click here to opt-out of future mailings.</A>";
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support. Do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
	}
}

How to use these code samples

You can use these code samples in Commerce Server 2002 solution sites to generate personalized e-mail content for Commerce Server 2002 ASP.NET site registered users. To do this, follow these steps:
  1. In a Commerce Server 2002 solution site that uses Visual Basic .NET, create the mail content page by using the TestEmail.aspx file and the TestEmail.aspx.vb file. In a Commerce Server 2002 solution site that uses Visual C#, create the mail content page by using the MSIBEmail.aspx file and the MSIBEmail.aspx.cs file.
  2. Visit the site, log on as a registered user, and then visit the mail content page to see whether the mail content page works.
  3. Create a list in Commerce Server 2002 Business Desk. To do this, follow these steps:
    1. In Campaigns, click List Manager.
    2. In List Manager, click the Import button.
    3. In the Import a List dialog box, click From SQL Database under List source.
    4. In the Import a List dialog box, type a name for the list. For example, type MyDirectMailList.
    5. In Commerce Server Manager, expand Commerce Server Manager, expand Global Resources, expand Profiles, and then copy the Profiles connection string. Then, in the Import a List dialog box, paste this connection string in the Connection string box.
    6. In the SQL query box, add the following sample query.
      select u_email_address As rcp_email, g_user_id as rcp_guid from UserObject where i_user_type=1
    Note Registered users must exist before you create this list.
  4. Create a direct mail campaign.

    Note For more information about how to create a direct mail campaign, see the "Setting up a Direct Mail Campaign" section of the Commerce Server 2002 documentation.
  5. In the direct mail definition, in the File path or URL containing message body box, type the URL of the MailContent.aspx file. For example, type the following URL:
    http://myCommerceServer/myCommerceSite/MailContent.aspx
  6. Send test e-mail messages to the list that you created in step 3.

↑ Back to the top


Keywords: KB889879, kbinfo

↑ Back to the top

Article Info
Article ID : 889879
Revision : 3
Created on : 8/23/2005
Published on : 8/23/2005
Exists online : False
Views : 413