Microsoft KB Archive/889879

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

Article ID: 889879

Article Last Modified on 8/23/2005

-

APPLIES TO


 * Microsoft Commerce Server 2002 Standard Edition
 * Microsoft Commerce Server 2002, Service Pack 3 (SP3)
 * Microsoft Commerce Server 2002 Service Pack 1

-



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.''



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 &quot;More Information&quot; section. These code samples are provided as-is. You must modify these code samples for custom Commerce Server 2002 ASP.NET sites.



Code sample in Visual Basic .NET
The following code sample is the TestEmail.aspx file. <%@ Page Language=&quot;vb&quot; AutoEventWireup=&quot;false&quot; Codebehind=&quot;TestEmail.aspx.vb&quot; Inherits=&quot;Microsoft.CommerceServer.Site.TestEmail&quot;%> <!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>   TestEmail         

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

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

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

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

COLOR:blue;

FONT-FAMILY:Tahoma;

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

mso-bidi-font-size:10.0pt&quot;>

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

'MS Mincho'&quot;><o:p></o:p> <p class=&quot;MsoPlainText&quot;><b><span style=&quot;FONT-SIZE:12pt;

COLOR:blue;

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

mso-bidi-font-size:10.0pt&quot;><![if

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

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

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

mso-fareast-font-family:'MS Mincho'&quot;>

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

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

COLOR:navy;

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

COLOR:navy;

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

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

'MS Mincho'&quot;>__________________________________________

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

FONT-FAMILY:Verdana;

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

mso-bidi-font-size:10.0pt&quot;>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> </i> <p class=&quot;MsoPlainText&quot;><i><span style=&quot;FONT-SIZE:8pt;

FONT-FAMILY:Verdana;

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

mso-bidi-font-size:10.0pt&quot;> <asp:Label id=&quot;lblOptLink&quot; runat=&quot;server&quot;>opt-out Link</asp:Label> <o:p></o:p> </i> </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


 * 1) Region &quot; Web Form Designer Generated Code &quot;

'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


 * 1) 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(&quot;MyProfile is nothing&quot;) Else FirstName = (MyProfile.Properties(&quot;GeneralInfo.first_name&quot;).Value).ToString LastName = (MyProfile.Properties(&quot;GeneralInfo.last_name&quot;).Value).ToString

lblSentDate.Text = SentDate lblName.Text = FirstName + &quot; &quot; + 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 = &quot;<A HREF='&quot; + CommerceContext.Current.QueryStringBuilder.BuildUrl(&quot;default.aspx&quot;, False) + &quot;'>Come see us today!</A>&quot; End If   End Sub

End Class

Code sample in Visual C#
The following code sample is the MSIBEmail.aspx file. <%@ Page language=&quot;c#&quot; Codebehind=&quot;MSIBEmail.aspx.cs&quot; AutoEventWireup=&quot;false&quot; Inherits=&quot;Microsoft.Solutions.Applications.MSIBEmail&quot; %> <!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot; > <HTML>  MSIBEmail <meta name=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 7.0&quot;> <meta name=&quot;CODE_LANGUAGE&quot; Content=&quot;C#&quot;> <meta name=&quot;vs_defaultClientScript&quot; content=&quot;JavaScript&quot;> <meta name=&quot;vs_targetSchema&quot; content=&quot;http://schemas.microsoft.com/intellisense/ie5&quot;> </HEAD> <body MS_POSITIONING=&quot;FlowLayout&quot;> <table style=&quot;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&quot; cellSpacing=&quot;0&quot; cellPadding=&quot;0&quot; bgColor=&quot;#ffff99&quot; border=&quot;1&quot;> <td width=&quot;655&quot; valign=&quot;top&quot;> <p class=&quot;MsoPlainText&quot;><span style=&quot;FONT-FAMILY:Tahoma;

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

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

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

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

COLOR:blue;

FONT-FAMILY:Tahoma;

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

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

'MS Mincho'&quot;><o:p></o:p> <p class=&quot;MsoPlainText&quot;><b><span style=&quot;FONT-SIZE:12pt;

COLOR:blue;

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

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

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

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

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

COLOR:navy;

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

COLOR:navy;

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

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

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

FONT-FAMILY:Verdana;

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

mso-bidi-font-size:10.0pt&quot;>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> </i> <p class=&quot;MsoPlainText&quot;><i><span style=&quot;FONT-SIZE:8pt;

FONT-FAMILY:Verdana;

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

mso-bidi-font-size:10.0pt&quot;> <asp:Label id=&quot;lblOptLink&quot; runat=&quot;server&quot;>opt-out Link</asp:Label> <o:p></o:p> </i> </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 description for MSIBEmail. ///    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[&quot;GeneralInfo.first_name&quot;].Value).ToString; LastName = (MyProfile.Properties[&quot;GeneralInfo.last_name&quot;].Value).ToString;

lblSentDate.Text = SentDate; lblName.Text = FirstName + &quot; &quot; + 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 = &quot;<A HREF='&quot; + CommerceContext.Current.QueryStringBuilder.BuildUrl(&quot;default.aspx&quot;, false) + &quot;'>Come see us today!</A>&quot;; //Opt-out.asp is another page that you must work on if you need this feature. lblOptLink.Text = &quot;<A HREF='&quot; + CommerceContext.Current.QueryStringBuilder.BuildUrl(&quot;opt-out.aspx&quot;, false) + &quot;'>Click here to opt-out of future mailings.</A>&quot;; }       }

#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); }       ///         /// Required method for Designer support. Do not modify /// the contents of this method with the code editor. ///        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: <ol> <li>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.</li> <li>Visit the site, log on as a registered user, and then visit the mail content page to see whether the mail content page works.</li> <li>Create a list in Commerce Server 2002 Business Desk. To do this, follow these steps: <ol style="list-style-type: lower-alpha;"> <li>In Campaigns, click List Manager.</li> <li>In List Manager, click the Import button.</li> <li>In the Import a List dialog box, click From SQL Database under List source.</li> <li>In the Import a List dialog box, type a name for the list. For example, type MyDirectMailList .</li> <li>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.</li> <li> 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 </li></ol>

Note Registered users must exist before you create this list.</li> <li>Create a direct mail campaign.

Note For more information about how to create a direct mail campaign, see the &quot;Setting up a Direct Mail Campaign&quot; section of the Commerce Server 2002 documentation.</li> <li>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:// / /MailContent.aspx

</li> <li>Send test e-mail messages to the list that you created in step 3.</li></ol>

Additional query words: Direct Mailer Commerce Server 2002 Impersonated Mail ServiceReminder

Keywords: kbinfo KB889879

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.