Friday, March 25, 2011

Using Gmail Account to Send Emails

Sending Email using Gmail Account from your Application

The following piece of code will let you send email using Google server. Just replace network credentials with your Google user name and password.


private void button_send_Click(object sender, EventArgs e)
{
//Detailed Method

MailAddress mailfrom = new MailAddress("sender@gmail.com");
MailAddress mailto = new MailAddress("receiver@abc.com");
MailMessage newmsg = new MailMessage(mailfrom, mailto);

newmsg.Subject = "Subject of Email";
newmsg.Body = "Body(message) of email";

//For File Attachment, more file can also be attached
Attachment att = new Attachment("C:\\...file path");
newmsg.Attachments.Add(att);

SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("username","password");
smtp.EnableSsl = true;
smtp.Send(newmsg);

//Alternative Short Method

SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("username","password");
smtp.EnableSsl = true;
smtp.Send("sender@gamil.com", "receiver", "subject", "Email Body");
}


Note: Before providing credentials, you need to set UserDefaultCredentials to false.

The above mentioned settings are for Gmail, but you can also use other SMTP servers.

Have a nice time.

Tuesday, March 15, 2011

jQuery plugin that adds a gmail-like confirm-before-exit feature to a form

* jQuery

If you use Gmail service, you must have noticed that after you try to close a tab which contains an unsaved draft, a confirmation window pop-ups, asking if you are sure about closing the unsaved draft.



I tried to implement this feature in my form, but eventually I found out that the Opera browser does not support the window.onbeforeunload event. After that I found a small jQuery plugin, called FormNavigate that attaches to form’s onchange the window.onbeforeunload event. This plugin still doesn’t solve the Opera problem, but its usage is quite simple and intuitive.

$("YourForm").FormNavigate("YourMessage");



When I looked over the Gmail’s js-code once again, I noticed that when a user tries to click on any link, confirm is triggered, and thereafter on windows close or page refresh the onbeforeunload event is triggered. It solves partially the Opera problem (even thought we still can’t handle the window close/refresh action, at least we can intercept the attempt to leave the page by clicking a link).

Therefore I decided to improve the above-mentioned script, so that make it work likewise the Gmail script does.

$("YourForm").FormNavigate({
message: "The form has been changed! \n Are you sure you want to close this page?",
aOutConfirm: "#DivID a.confirm, #DivID2 a"
});



The aOutConfirm specifies the links, which will raise the warning message when a user clicks on them. If you don’t specify any, the message will be raised for any link that has been clicked.

Original script
Improoved script
Demo of the improoved script

Thursday, March 3, 2011

What can you Write in 128 Bytes?

In contrast to the ever increasing memory available, a number of programmers are choosing to demonstrate their coding prowess by squeezing as much as possible into an incredibly tiny program. It has become a popular passtime to code an impessive graphical display in either 128 or 256 bytes.

Before zooming off to try this for yourself, why not check out some of the competition? Five of the best are listed below, and also my own contribution.

OKOOKO by Ind. The coloured rings sway gently. Good use of colour.
InterferenceInterference by New Generation Crew. A fast moving interference pattern between two sets of rings. Supplied with source code.
CtvereckyCtverecky by RRRola. A chaotic, spiralling pattern. Only 93 bytes long. Supplied with source code.
CorkscrewedCorkscrewed by lord Kelvin - a smooth, gentle swirl slowly draws you in. Great use of colour. Supplied with source code.
Color DreamColor Dream by Digimind - a chaotic looking swarm of spheres. Impressive in motion.
Plasma WavePlasma Wave by John Metcalf - my own contribution. A display of flowing plasma. Supplied with source code.

O my God There is no more Ctrl+N in SQL 2008

Ctrl+N is not working in SSMS (2008). We can easily fix it by changing the KeyBoard to SQL 2000 from Standard. To Change it

Tools --> Options --> Environment --> Keyboard --> Keyboard Schema Change it to SQL Server 2000.

Now you find that Ctrl+N is working ........

An awesome short cut to format SQL Code lines.

When you opened a stored procedure and pasted it on Query Editor it look likes a bulky element and obviously difficult to understand. Just select the entire code and Press


Shift + K+ \

Nemesis

Nemesis is a command-line network packet crafting and injection utility for UNIX-like and Windows systems. Nemesis, is well suited for testing Network Intrusion Detection Systems, firewalls, IP stacks and a variety of other tasks. As a command-line driven utility, Nemesis is perfect for automation and scripting.

Nemesis can natively craft and inject ARP, DNS, ETHERNET, ICMP, IGMP, IP, OSPF, RIP, TCP and UDP packets. Using the IP and the Ethernet injection modes, almost any custom packet can be crafted and injected.


Author: Jeff Nathan jeff@snort.org>


Source code: nemesis-1.4.tar.gz (Build 26) (DSA sig)
Windows binary: nemesis-1.4.zip (Build 26) (DSA sig) (includes LibnetNT)


Unix-like systems require: libnet-1.0.2a, and a C compiler (GCC)
Windows systems require: libnetNT-1.0.2g and either WinPcap-2.3 or WinPcap-3.0
Supported platforms: *BSD, Linux, Solaris, Mac OS X, Microsoft Windows


Special thanks: Mike Schiffman (libnet author)

Man upgrades Windows 1.0 to Windows 7



One man has captured every install of Windows from 1.0 through to 7 and shared it with the world via YouTube.

The video details install processes and the UI for each version of Windows over the past 25 years and most importantly the upgrade process. The only exception is Windows ME, missing as you can only upgrade to ME or 2000 and not both. The video creator, Andrew Tait, used VMWare to install each version and started by installing MS-DOS 5.0 to prepare for the Windows 1.0 installation. Monkey Island and Doom 2 are both installed to test upgrade compatibility throughout the years.

Microsoft first introduced Windows 1.0 on November 20, 1985. Since the introduction of Windows, the operating system has dominated the personal computer market. Microsoft’s market share worldwide for Windows currently sits at 91%, which is significantly higher than its rivals, Apple and Linux. Windows has seen a number of key changes throughout its life and the video (below) demonstrates the majority of these.

However, it hasn’t been all rosy over the past 25 years. Several run-ins with authorities worldwide have forced Microsoft to un-bundle key components of its operating system such as Internet Explorer and more recently Windows Media Player. A notorious court case with the American Department of Justice, which ended in 2001, saw Microsoft forced to share its systems, APIs source code and records with a specially allocated panel of experts. In the years after 2001 it also saw Microsoft un-bundling Internet Explorer from the Windows shell. Microsoft also got into trouble with the European Commission on several occasions. In 2003 the EU ordered Microsoft to provide a version of Windows without Windows Media Player, labeled Windows N. In January 2009 the EU also forced Microsoft to create a version of Windows without Internet Explorer. The company created the version, known as Windows 7 E, but later scrapped it in favor of a “browser ballot” screen that would allow consumers to pick their preferred browser.

If you’re a Windows fan and have 10 minutes free then check-out the nostalgic video below, thanks to The Next Web for spotting this classic.