Tuesday, April 21, 2009

GMail SMTP Setting To Send Email From ASP.net Application

First of all , It is required to configured GMail.

1. Create Gmail account or use existing if you already have it.
2. Log in into Gmail.
3. Go Settings.
4. Go Forwarding and Enable IMAP/POP3
5. In that go to last section and enable IMAP.

Now in your Web Application / Web Site project , open web.config. Add following to web.config.

<system.net>
    <mailSettings>
      <smtp deliveryMethod="Network">
        <network host="smtp.gmail.com" port="587" userName="username@gmail.com" password="password" />
      </smtp>
    </mailSettings>
  </system.net>

GMail IMap Service runnig at port 587 so you must required to configured that. Also Gmail required SSL authentication so it is required to enable ssl for SMTPClient.

MailMessage message = new MailMessage();
message.From = new MailAddress(
from@gmail.com);
message.To.Add("to@gmail.com");

SmtpClient client = new SmtpClient();        
client.EnableSsl = true;            
client.Send(message);

Yuo can not enable SSL in web.config so you must required to configure it explicitly.

Friday, April 17, 2009

WebService Authenticate against proxy server.

When proxy server configured for PC or in a network , if it require authentication to make certain request then you have to use following code.

Error: (407) Proxy Authentication Required.

Here i am taking example of SharePoint List service. I added reference of SharePoint List Service.


ListSerivce lst = new ListSerivce();
//Get Default Proxy Setting
IWebProxy proxy = System.Net.WebRequest.DefaultWebProxy;
// Authenticate using network credential. In My case i need authentication using windows account.
proxy.Credential = new System.Net.NetworkCredential(“username”,”password”,”domain”);
lst.Proxy = proxy;
// Make Call to WebService Method.

You can even find System.Net.WebProxy.GetDefaultProxy() return default proxy setting but it is deprecated to better to use WebRequest.DefaultWebProxy.

You can even configure your own webproxy

Lists lst = new Lists();
System.Net.WebProxy proxy = new WebProxy();
proxy.Address = new Uri("
http://proxy:8090");
proxy.Credentials = new NetworkCredential ("username", "password", "domain");
lst.Proxy = proxy;

In both case credential pass as NetworkCredential but you can use CredentialCache to pass other type of credential.

Please give comment on this. Also if you have any better idea please free give your suggestion.

Thursday, April 9, 2009

CrystalReport redistribution package

This is just a small information about Crystal Report redistribution package. You can fine different packages related to Visual Studio at following location

“<system drive>:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages”

At this location you can different directories that contains .exe or .msi related to Visual Studio 2008 installation.

Friday, April 3, 2009

WSE 3.0 Setting Tool For Visual Studio 2008

WSE 3.0 Setting Tool not available in VS 2008. Here i am explaining steps required to enable it in Visual Studio 2008.

1 . Download Following Tool
     WSE 3.0 Tools
2.  Install that MSI File.
     “Basically that installation is for Visual Studio 2005.”
3.  After installation you find one file at following location.
     C:\Documents and Settings\All Users\Application Data\Microsoft\MSEnvShared\Addins
      Here i assumed that your OS is installed at C:\.
4. At that location you find this file “WSESettingsVS3.Addin”.
5. Open file in Notepad , you find following XML content.   

  <HostApplication>
    <Name>Microsoft Visual Studio Macros</Name>
    <Version>8.0</Version>
  </HostApplication>
  <HostApplication>
    <Name>Microsoft Visual Studio</Name>
    <Version>8.0</Version>
  </HostApplication>

change it to

  <HostApplication>
    <Name>Microsoft Visual Studio Macros</Name>
    <Version>9.0</Version>
  </HostApplication>
  <HostApplication>
    <Name>Microsoft Visual Studio</Name>
    <Version>9.0</Version>
  </HostApplication>

save that file.
6. Open Visual Studio , Tools – > Options –> Environments

image

Add Following
“C:\Documents and Settings\All Users\Application Data\Microsoft\MSEnvShared\Addins”

(Note : In Image it displayed D:\ as my os is on D Drive.)

7. Close all instance of Visual Studio.

8. Open it again , create web service application . Now you can se that WSE 3.0 Setting option enable.

Thursday, April 2, 2009

How to get assembly name for registration ?

When assembly added into global assembly cache and there is need for adding that assembly to web.config assemblies section.

<compilation debug="false">
          <assemblies>
            <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
            </assemblies>
</compilation>

Now there is need to add System.Web.Extensions assembly , for that you need assembly detail with its public key token to register.

Easiest way to get that detail is 

1. Go to run and type assembly.

run

it will open following window.

window1

2. Now select assembly , for example system.web.extensions , then go to edit menu and select option Copy display name as shown in following image.

window2

3. Now paste data.

image

you get all detail to register assembly. Enjoy… !