How to Test Emails during the Development?

January 25, 2011 Leave a comment

It is very common need to test whether Emails are going to recipients or not, during our development. But your development environment may not support to send the emails.
Below are  the few such environments.
Note: Here I am considering the developing .NET application, either WinForms, or WebForms.

  1. Using Windows XP system for developement.
  2. You don’t have IIS.
  3. You have IIS, but without SMTP server configuration.
  4. In case of ASP.NET web application, you are using ASP.NET Development Server (Cassini)

In such cases, the best workaround to test emails is – Configure an 3rd party SMTP server.
Coming to the point of interest for this post…that is SMTP4Dev (http://smtp4dev.codeplex.com/). It is a dummy SMTP server, sits in the system tray and does not deliver the received messages. The received messages can be quickly viewed, saved and the source/structure inspected. Useful for testing/debugging software that generates email.

How to use it?

Step#1: Download and install it. You will find it in the system tray

And below is its interface

Step#2: Configure (Domain name, IP, Port) and start listening

Step#3: Now, your SMTP server is ready. Before testing this, add configuration setting to web.config file.
    <mailSettings>
      <smtp>
        <network host=”localhost” port=”31” defaultCredentials=”true” enableSsl=”false”  />
      </smtp>
    </mailSettings>
  </system.net>

Step#4: Below is the code snippet to test it.

SmtpClient mailClient = new SmtpClient();
MailMessage msg = default(MailMessage);
msg = new MailMessage();
msg.From = new MailAddress(“sentFrom@EmailAddress.com”);
msg.To.Add(“ypradeep23@hotmail.com“);
msg.Subject = “TEST Subject”;
msg.Body = “TEST Message”;
msg.IsBodyHtml = true;
mailClient.Send(msg);

Step#5: Once it done, you will have the mail in SMTP4Dev window, as shown below…

Step#6: In this dialog, “Inspect”, “View” are useful commands.
Inspect, will shows you the inner details of the email (like… source, headers, body… )

And you can “View” the mail in Outlook client / Windows Live mail client.

We are done with Email testing during the development it self. Very useful and hope the same for you.
Also, there is one more alternative to test emails using deliveryMethod=”SpecifiedPickupDirectory”. Refer the below links…
http://www.antix.co.uk/Projects/SMTPServerForDevelopers
http://chillicode.wordpress.com/2009/07/25/send-emails-with-out-smtp-server/

– Pradeep.

Advertisements
Categories: Uncategorized

TFS – List out all changes between 2 dates

December 21, 2010 Leave a comment

List out all changes between 2 dates

  1. Need to use “C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\tf.exe”; Run it from command prompt.

Command:  “tf history -noprompt -server:<tfs server> <Project Path> -version:<Date1>Z~<Date2>Z -recursive -format:detailed -login:<UserName>,<Password> > c:\checkedout.txt”

Ex: tf history -noprompt -server:http://mytfs-server:8080 $/MyProject/Release/Dev2 -version:D2010-11-01T01:01:01Z~D2010-12-20T20:00:00Z -recursive -format:detailed -login:crm\pradeep,password > c:\checkedout.txt

Categories: Uncategorized

TFS – List out all checkout files

December 21, 2010 Leave a comment

Some times you may need to listed out all the checkedout files in an TFS project. This is very frequent task in my project. There is a command line tool available for to do this.

  1. Need to use “C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\tf.exe”; Run it from command prompt.
  2. Command:  “tf.exe status $/MyProject/Release/Dev2 /login:crm\pradeep,xxxx /user:* /s:http://mytfs-server:8080 /recursive > c:\checkedout.txt”

    Project name = $/MyProject/Release/Dev2
    User Name = crm\pradeep
    Password = xxxx (replace with your password)
    Users = * (/user:*, consider all users)
    TFS Server = http://mytfs-server:8080
    Output = c:\checkedout.txt

  3. References:
    http://msdn.microsoft.com/en-us/library/9s5ae285.aspx
    http://clay.lenharts.net/blog/2008/01/28/listing-checked-out-files-in-team-system-tfs/
  4. To avoid manual work in executing this from command prompt, create a batch file. Below is the batch file, and just click on it. (Need to change your password)@echo off
    echo *** LIST OF CHECKED-OUT FILES FROM A TFS SERVER ***CD C:\Program Files\Microsoft Visual Studio 8\Common7\IDE

    tf.exe status $/MyProject/Development  /login:crm\pradeep,password /user:* /s:http://comrcn01clademo:8080 /recursive > c:\checkedout.txt

    REM for specific User
    REM tf.exe status $/MyProject/Development /login:crm\pradeep,password /user:crm\pradeep /s:http://mytfs-server:8080 /recursive > c:\checkedout.txt

    START c:\checkedout.txt
    echo *** Completed ***
    REM pause

  5. If you are using VS 2010, TFS 2010… try TFS Power Tools
Categories: Uncategorized

Visual Studio – Find using Regular Expressions

September 23, 2010 Leave a comment
Most of the times we using Ctrl+F (Find) feature in Visual Studio with commen Find options like "Match case", "Match Whole Word"…
But rarely we use option "Use by Regular expression" (Need to ckeck Use and select Regular expression / Wildcard).
 
 
 
Recently I started using this, and found it is very useful. Here are the few examples…
  1. <pra – Find words start with "pra"
  2. deep> – Find words ends with "deep"
  3. <p[a-z]+deep> – Find words which starts with "p" and ends with "deep"

I agree, these are very simple examples… but I hope it is useful introduction.

References:
http://msdn.microsoft.com/en-us/library/2k3te2cs(VS.80).aspx
http://blogs.msdn.com/b/saraford/archive/2007/11/02/did-you-know-how-to-use-wildcards-and-regular-expressions-while-searching.aspx

 

 
Categories: Visual Studio

Add Row to ASP .NET Listview at Clientside

April 18, 2010 2 comments


Point of Interest:
Add row to ASP .NET Listview at client side.
Using…ASP .NET, C#, Visual Studio 2008, Listview Control, ASP .NET AJAX, JQuery, JSON, Serialization, Linq to Sql.

Problem:
All List controls, like Datagrid, Gridview, Listview, in ASP .NET has set set of features to work with records. These features includes Edit, Delete, Select, Insert. All these features require a full postback to server to complete its operation. I want to avoid these postbacks.

Requirement:
I have a  “property” table in my database, and goal is to implement CRUD operation on that table along with the below additional requirements.

  1. There should be no postbacks for adding new row and delete
  2. All rows  should be displayed in a editable mode
  3. User should able to add new record at client side only.

Implementation:

Database

  1. Take a new empty solution “AddRowClientSide”and a web a web application project.
  2. Add a database into APP_DATA folder
  3. Open database and create table.
    image
    In this demo, all CRUD operations are implemented on PROPERTY table. There is no business behind this table, so this table as it is.
  4. Database is attached in the source, at the end of article.

Data Access

  1. Create a “DataAccess” folder in project
  2. Add new LINQ to SQL dbml file to project.
    image
  3. Open Property.dbml and drag tables and stored procedures, as show below.
    image
  4. This will create and classes and methods for your CRUD operations.

Business Logic Layer

  1. Add a folder BLL to the project.
  2. Add PropertyBR class file to BLL folder.
  3. Add methods to GetProperties, AddProperty, DeleteProperty as below
    image

Application Layer:

  1. Here is the final output…
    image
  2. Create required styles.
  3. Add jquery-1_1.4.2.min.js to project
  4. Add ASP.NET AJAX script manager to page. This renders the required script files to client for JSON serialization. Also we need it to use any MS ASP.NET AJAX related controls like Updatepanel.
  5. Note that, one of our additional requirement is, new row should be added at client side. But the controls added at client won’t be available to server. So to persists the data I am using hidden fields. Lets add three hidden fields for data persistence.

    hidNewRowCount: Default=0, when ever we add a new row this value will be incremented by one.
    hidRemovedIDs: When user removes a row by clicking on [X] link, ID of respective row will be saved in to this in CSV format. Ex: 1,2,3
    hidNewRowData: Data entered in newly created rows will be saved into this in JSON format.

  6. Add a Listview to page, to display data. This is new control in .NET Framework 3.5, gives more control to developer. INSERT template, GROUP templates are some of the new features in it.
  7. When ever user clicks on ADD button a new row should be added to Listview. So define a template for new row, separately and hide it from user eyes.
  8. Lets discuss some important point about the template definition.
    image
    Added a custom attribute “status” to represent the status of each row.
    Status= 0: Bind (All the rows binded at server)
    Status= 1: AddNew at Client Side
    Status=-1: Deleted (Status will be set to –1 and row will be hidden when deleting row with status is 0 i.e, row from server; But row with status = 1 will be deleted permanently.)
  9. Adding a new row…
    On ADD button’s click event clone the hidden template using JQuery’s Clone() function, add to table. Each added row will be assigned with a new ID.
    image
  10. IDs of deleted rows will be maintained in hidRemovedIDs
  11. How to send new row data to server? There can be multiple answers for this questions.
    – Concatenate the properties using some delimiters
    – Fill all Properties into a JavaScript object and serialize.
    Either way, we need to store it to some hidden field, to send to server.
  12. I want to go for JavaScript objects, instead of  delimiter strings. Here is the way to do it.
    image
  13. In the server side we can de-serialize the Json object
    image 
  14. I know, its not a detailed narration of the work done, just play with the source code to feel the fun in it.
  15. Finally, a small tip to show the row number…
    image
    image
  16. Download the source code from here
  17. Here are very good links I referred in doing this. Thanks to all for their good work.
    JQuery
     
    Using ListView Control
     
    JSON Serialization

Hope it helps…!
Pradeep.

 

    Categories: .NET Development

    Chaching with Sql Server 2005 Query Notifications

    February 24, 2010 Leave a comment
    Here is the POC on implementing caching in ASP .net, with SQL Server 2005 Query Notifications.
    Download the source code here
     
    Challenges in troubleshooting:
     
     
    Additional references
    Categories: Database

    Getting Client Timezone in ASP .NET

    February 22, 2010 Leave a comment
    ASP .net Provides dataTime functions like UtcNow, to get the UTC time at present. With DateTime.Now, DateTime.UtcNow, we can calculate Time offset between Server and UTC.
     
    But how to find out the offset of client?, the end user who is browsing our site from a different timezone.
    For findout the javascript’s Date() object provides a method called "getTimezoneOffset()", which returnes the offset value in Minutes.
     
    Refer the blow links from more information.
    Categories: HTML & Javascript