Search This Blog

Tuesday, December 15, 2009

ShallowCopy and Deepcopy

Difference between Shallow Copy and deep copy.

Shallow copy copy creates new object and copies references in the object and wont copy the referenced objects.

Eg: "X" is an object and having references to objects "A" and "B" .
Now object "X1" is created as shallow copy to object "X" . now X1 contains references to "A" and "B".
i.e both X and X1 are pointing to objects "A" and "B".If any non static variables present in "X" those are also copied directly bit-by-bit into "X1".

In deep copy "X1" contains references to "A1","B1" which are copies of "A"&"B".

Best Regards
Palle Technlogies
http://techpalle.com

Wednesday, November 18, 2009

send mail from asp.net to gmail

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net.Mail;

// Now open your .aspx page replace the page_load with below code

protected void Page_Load(object sender, EventArgs e)
{
MailMessage message = new MailMessage();

try
{
MailAddress fromAddress = new MailAddress("pallelokanathareddy@gmail.com", "Lokanatha");
message.From = fromAddress;
message.To.Add("pallelokanathareddy@gmail.com");
message.Subject = "Feedback";
message.IsBodyHtml = false;
message.Body = "Hello Lokanatha";
sendmails(message);
Label1.Text = "Email successfully sent.";
}
catch (Exception ex)
{
Label1.Text = "Send Email Failed." + ex.Message;
}
}

public void sendmails(MailMessage mm)
{
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = "pallelokanathareddy@gmail.com";
NetworkCred.Password = "youe actual gmail password for the mail id mentionaed in the above code"; ;
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);

}


Smtp settings:

note: smtp server should be installed in your computer.your system must have internet connection
1.go to start>run
2.type "inetmgr" in the run press ok
3.in the newly opened internet service manager navigate to "default smtp virtual server"
4.go to domain right click new>domain
5.select remote and click next"smtp.gmail.com" and click finish.
6.now go to "default smtp virtual server" right click choose "Properties" and click.
7.in the ip address dropdown choose your system ip.
8.go to "access" tab click on "Relay"
9.selectradio buton "only the list below" and also check "allow all the computers which success fully authenticate to relay.regardless of the list above" click ok.
10.in the connection select "only the list below" click ok.
11.click on "Authentication" button choose "Anonymous Acess" click ok.
12.close your iis window.


Now run the code it sends email to the to address.