-
My move to Athens
-
Well, I have been asked to move to Athens and work on a project in my company. It was a tough decision to make because i have to leave my country and try to live there for more than 3 months. I will try to keep my blog alive as well as for my contributions to the asp.net forums members.
Meanwhile, You can leave comments on any blog post i already made and i will try my best to answer it as soon as possible.
Regards,
-
Send Personalized Emails using System.Net.Mail
-
In this blog post, We will learn how to send personalized emails to our clients. At first, Just create a txt file called "MailTemplate.txt" in your application root folder containing the below
Dear <user>,
This is a test for the process of sending personalized emails taking advantage of the power of System.Net.Mail introduced in ASP.NET 2.0
Best Regards,
<company>
What we will do in the next section is to merge the above template with the MailMessage Class. (user and company will be replaced through our code).
// Create a dictionary generic collection and add the values of user and company
Dictionary<string, string> d = new Dictionary<string,string>();
d.Add("<user>",User.Identity.Name);
d.Add("<company>","MyCompany");
// Create instance of the MailDefinition Class
MailDefinition md = new MailDefinition();
// Set its Body file name to the template already created
md.BodyFileName = "MailTemplate.txt";
// use the CreateMailMessage function of the MailDefinition class to set the To, Collection
MailMessage ms = md.CreateMailMessage("haissam50@hotmail.com", d, new LiteralControl());
// Set the from Property
ms.From = new MailAddress("haissam@haissam.com");
// Set the subject
ms.Subject = "Personalized Email";
// Create an instance of the SmtpClient class
SmtpClient sm = new SmtpClient();
// Send the email
sm.Send(ms);
Of course, you need to configure the Mail Settings in your web.config file.
Hope this helps
-
MasterType directive in Content Page
-
In this blog post, An example will be provided to demonstrate the benefit of the MasterType directive.
Suppose we have a page associated with a master page. In the master page, we have a Label control (Label1) which we need to access its text property and change it from the content page. We create a public property in the master page called LabelText
public string LabelText
{
get
{
return Label1.Text;
}
set
{
Label1.Text = value;
}
}
To gain access to the master page file in the content page, Add the below directive to the content page
<%@ MasterType VirtualPath="~/MasterPage.master"%>
When ASP.NET realizes the existance of this directive, it generates a strongly typed property "Master". this property will give you access to the MasterPage file. So directly in the content page code behind you would use the below instead of trying to use the FindControl method.
Master.LabelText = "Testing the MasterType directive effect";
Hope this helps