How to Send Emails from Google SMTP

I came into an issue where I need to send an email from my website.. I don’t have an SMTP service installed on my web server and I didn’t want to go into that path for many of my personal reasons. so I decided to go with Google SMTP service as it is free as well as it is accessible from anywhere.. to accomplish this task it took from me 15 minutes.. so I thought of sharing my code with you as well

public void SendEmail ()
{

var client = new SmtpClient(“smtp.gmail.com”, 587)
{

Credentials = new NetworkCredential(“EmailAccountUserName@gmail.com”, “Password”),
EnableSsl = true;

};

client.Send(“EmailAccountUserName@gmail.com”, “EmailAccountUserName@gmail.com”, “EmailSubject”, “EmailBody”);

}

I hope you will find this useful…

I hope

The Module DLL C:\Windows\system32\inetsrv\rewrite.dll failed to load. The data is the error.

Recently I was trying to host a website that is building on top of .net 4.0 into my IIS 7.X server. The framework installed and configured correctly but the site was not being able to show up. The main problem was the app pool turning OFF whenever I was trying to send request to the website. That was a very strange thing for me.

I checked the event log and I found the IIS is logged the following error message into my Event log

“The Module DLL C:\Windows\system32\inetsrv\rewrite.dll failed to load.  The data is the error.”

After research and investigation on why this error message showing up I found the “Rewrite.dll” is missing thus I need to install it.. This dll supposed to be found on the following path  “C:\Windows\System32\inetsrv”. the URL Rewrite is a component provided by Microsoft and it is complementary for the IIS to help IIS being able to resolve the routes

To install it, you need to download on of the installed (based on you OS archi) and install it.

Download IIS Rewrite Module (x86)

Download IIS Rewrite Module (x64)

I hope  this would help you fixing the issue that you are looking to fix.

Generic JQuery Confirmation Message

Did you ever come to a point where you get tired from the limitation from the browser default confirmation message… I came into that point so many times… but also I didn’t like the idea of keep doing workarounds on this.. so I built a Generic Confirmation Message using JQuery.. it is basically much flexible than what browser confirmation message do for us…. My generic confirmation message is built on MVC solution, so I’m using the flexibility that MVC providing me….

let’s assume you want to display a confirmation message on deletion operation… Below is a JQuery method that will show the confirmation message and depends on a call back Java Script method to be called in case the user click on the  “Delete” button.

/*Show up a confirmation delete message*/
function ConfirmDelete(message, callback) {
    var $deleteDialog = $('<div>Are you sure you want to delete ' + message + '?</div>');

    $deleteDialog
        .dialog({
            resizable: false,
            //height: 200,
            title: "Delete Record?",
            modal: true,

            buttons: {
                "Delete": {
                    click: function () {
                        $(this).dialog("close");
                        callback.apply();
                    },
                    class: "btn btn-default",
                    text: "Delete"
                },
                Cancel:
                    {
                        click: function () {
                            $(this).dialog("close");
                        },
                        class: "btn btn-default",
                        text: "Cancel"
                    }
            }
        });
};
I think the next question will be is how to use above method… I’ll present an example where I want to delete a record from a grid. so I built a method that will do a JQuery Ajax call to server in order to delete the record… the Ajax post that will be made is depending on an href attribute attached the delete button or link on your page; meaning you need to provide a full info on your href; in MVC it is ‘/Record/Delete/{IdValue}’
/* Do Delete for error message*/
function DeleteRow($btn) {

    $.ajax({
        url: $btn.attr('href'),
        success: function (response) {
            $("#ajaxResult").hide().html(response).fadeIn(300, function () {
                var e = this;
                setTimeout(function () { $(e).fadeOut(400); }, 2500);
            });

            window.location = response.url;
        },
        error: function (xhr) {
            displayError(xhr.responseText, xhr.status); /* display errors in separate dialog */
        }
    });

    return false;
};
when user click on the button on the grid, you should call the following function; or similar one depending on your needs
 /*show Delete confirmation message*/

function DeleteGridRowConfirmationMsg(btn,recordName) {

    ConfirmDelete(recordName,
        function () {
            DeleteRow($(btn));

        });
    return false;
}
I hope this will help you on having a generic confirmation message on your site.. one last comment, make sure that you have JQuery UI script files imported into your project as well as into your web pages

Visual Studio 2013 news Update inside the Development IDE… Great Extension

Did you ever wanted to look into Visual Studio news feed inside the development IDE and have this news feed updated whenever there is new feed posted? The good news is this wish is becoming true now. You can do this by installing News Extension…The bad news is this extension is only available on Visual Studio 2013 and it is not available as the time of writing this post to any other Visual Studio versions.

After installing this extension on your visual studio; you will get a new button inside the Team Explorer window.. which will make you updated whenever there is a new news posted.

Unable to create the store directory while using Excel.Package dll

I have a web component that using Excel.Package dll to generate excel sheet. When I deployed my system to a new windows server 2003; I start getting strange error which is “Unable to create the store directory” .. after spending good amount of time doing research and making sure the deployment was completed correctly, I figured out what is the issue.. it is basically the Excel.Package couldn’t create special file while saving data to excel file. To fix this, all what you need to do is 2 steps:

1. make sure you have the following folder: C:\Documents and Settings\Default User\Local Settings\Application Data\IsolatedStorage
2. make sure you have the proper Read/Write permission for your user on above path. It is important to make sure the permission is correct and it is not inherited from the parent directory. Thus you need to copy the permission from parent directory and adjust the permission to make sure the proper user have the needed Read/Write permission.

Doing above 2 steps fixed the issue that I faced and made things working fine.. I want to emphasis on making sure the directory have the correct permission to read/write and its permissions is not inherited from parent directory.

Manage System.Transaction timeout

When using System.Transaction in .net framework; you may came across a timeout problem where you code needs longer time to run than the default timeout duration for System.Transaction.. this is because the System.Transaction will be aborted after few seconds which will rollback your changes.. to make the timeout longer than the default timeout duration, you need to adjust your code to do this, there is no configuration on IIS/appconfig level to accomplish that. the following code sample showing how to accomplish this from code perspective

TimeSpan timeoutDuration = TimeSpan.FromSeconds(180);
using(TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, timeoutDuration))
{


Scope.Complete();
}

The timeout default value is 60 seconds; if you want to have an infinite timeout; just set it to be 0.

You need also to change values on machine.config in case you made the timeout value more than 10 minutes. Because the machine.config has a configurable value to limit TransactionManager’s timeout to be 10 minutes at max.

TransactionManager is setting on top of the transaction object; thus it has the upper hand on it if you exceed the 10 minutes limit. The problem with TransactionManager is you can’t change the timeout default value programmatically and you need to update the machine.config to accomplish this. To do so change the following tag value on machine.config

<configuration>
   <system.transactions>
        <machineSettings maxTimeout="00:30:00" />
   </system.transactions>
</configuration>

Responsive Web Design

Responsive web design is a web design approach that is aimed at crafting sites to provide an optimal viewing experience, easy reading and navigation with minimal efforts of resizing, panning, and scrolling – across wide range of devices including mobile, tablets and desktop devices. Mainly the Responsive web design position the page content in a fluid, proportion-based grids, flexible images, and CSS3 media queries, an extension of the @media rule.

Mobile and tablet devices adoption is rapidly grow all over the world; thus it is becoming more critical to have websites that looking good in those devises and make users feel comfortable while using your website on small screens as well as on large screens. Based on recent stats on the market, the sales for mobile and tablet devices overtake the sales for desktop devices which is making to have your website looking good on those devices essential for your organization success.

When you start thinking of having website that looks good on mobile and tablet devices , you will have 2 options;

  • Build a separated website for mobile devices and another one for desktop.
  • Using responsive design technique to have single website that works on both desktop and mobile devices.

Both options are valid and debatable… each of these options has its own pros and cons. Which one to adopt and go with depends on your business and what factors to consider. It is not the target

 

Google in general is recommending to go with Responsive web design approach… it will help you a lot in many areas.. For me, I hate code duplication. For the marketing guys they hate to duplicate the marketing content in many places.. Responsive web design will help on solving both problems and make those things centralized in one place and get rid of the headache of duplicated code/contents.

SOLID Object-Oriented-Design Principles

One of the main principles of OOD (Object Oriented Design) is SOLID principles. SOLID is stands for :

1. Single Responsibility Principle:

This means the class has to have one and only one reason to responsibility. This responsibility should be encapsulated by the class.

2. Open/closed principle:

The open/closed principle states that software entities (classes, modules, functions, …etc) should be open for extension, but not for (closed) modification

This will be very helpful on the production environment where fixing and enhancing certain area is required without affecting other areas. thus you will go with extending the class and its behaviors without modifying the current existing code/methods

3. Liskov substitution principle:

means Substitute-ability; It states that, if SubclassA is a sub-type of MainTypeA, then objects of type MainTypeA may be replaced with objects of type SubclassA without altering any of the properties of that program

4. Interface segregation principle:

The main goal from this point is to make the software more maintainable and loosely coupled; thus easier to re-factor and change. Basically, we need to split the large interfaces into smaller interfaces so that the client classes will be aware of the methods/properties they concern about

5. Dependency inversion principle:

It is about decoupling software layers and making sure the software is loosely coupled. Basically this principle states 2 things:

– High-level modules/layers should NOT depend on low-level modules/layers. communication between modules and layers should go through abstractions.

– Abstractions should NOT depend on details and the Details should depend on abstractions.

 

 

IIS 7 – How to Resolve Error HTTPs 413: Request Entity Too Large

couple of days ago, I came across an issue where when user leave the web page idle and try to upload a file using JQuery-FileUpload; user was getting error 413. and sometimes users were getting “The page was not displayed because the request entity is too large.” error.

I increased the uploadReadAheadSize  value on IIS and that was enough to fix the issue; I did the followings:

  1. Launch “Internet Information Services (IIS) Manager”
  2. Select the site that you are hosting your web application under it.
  3. In the Features section, double click “Configuration Editor”
  4. Under “Section” select: system.webServer  then serverRuntime
  5. Modify the “uploadReadAheadSize” section to be like 20MB (the value there is in Bytes)
  6. Click Apply

The error is happening as during renegotiation step between your web browser and the IIS Server; the entity should be preloaded using SSL. and result is being larger than the default value which is ~49K

Fix Installer issue – FIX IT

while I was developing windows service using visual studio 2010, I came a cross an issue that prevent me from continue working. I wasn’t able to uninstall or install my service any more.  I was using windows installation project within Visual Studio on windows 7 PC.

I tried so many things with no luck. I even tried to use the command prompt commands trying to uninstall/install the service; but nothing could solve the issue. till I found a tool from MS that could successfully scan and fix the problem for me. The tool took like 10 min scanning my machine; but at the end it fixed the issue for me. here is the link to the tool http://support.microsoft.com/mats/Program_Install_and_Uninstall

Please let me know if this tool fix the issue for you as well or not?