Tuesday, July 22, 2008

Send Email .NET code using Gmail SMTP

To send email, we need a SMTP server and Google has provided it for free :) Just use this code to send email using your Gmail account.

public static void SendMail()

        {

            //Builed The MSG 

            System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();

            msg.To.Add("agus.santoso@plasmedia.com");           

            msg.From = new MailAddress("youremail@gmail.com", "Your Name",System.Text.Encoding.UTF8);

            msg.Subject = "Test mail using .net2.0";

            msg.SubjectEncoding = System.Text.Encoding.UTF8;

            msg.Body = "This is my msg Body";

            msg.BodyEncoding = System.Text.Encoding.UTF8;

            msg.IsBodyHtml = false;

            msg.Priority = MailPriority.High;           

          

            //Add the Creddentials 

            SmtpClient client = new SmtpClient();

            client.Credentials = new System.Net.NetworkCredential("youremail@gmail.com", "your password");

            client.Port = 587; 

            client.Host = "smtp.gmail.com";

            client.EnableSsl = true;

            object userState=msg;

            try

            {

                client.Send(msg);

                Console.WriteLine("success");

            }

            catch (System.Net.Mail.SmtpException ex)

            {

              Console.WriteLine("Send Mail Error");

            }

        }

Monday, July 21, 2008

SharePoint Document Library TreeView Browser WebPart

SharePoint have a nice way to organize your files in document library by using folders, just like Windows Explorer does. But it lacks one important feature, the treeview browser. That's what I need in my last project requested by my client. I found great SharePoint Document Library TreeView Browser WebPart, called SharePoint Stramit Document Library browser , made by Renaud Comte, Microsoft MVP. And the best part, it's free :) You could see the source code given by Renaud Comte too in the CodePlex.

There are 3 kinds of treeview here (the description quoted from CodePlex):
1. Static TreeView ,a simple TreeView WP load in one shot the document library hierachy
2. Dynamic TreeView, for large library, the loading append when you open a folder
3. Multiple TreeView, This WebPart load automatically all the document library on your local WSS site. It's a derived version of the dynamic treeview, so not big problem if there some huge lists.

To use it, just use stsadm.exe utility (read Sean Chase tutorial here, see point 22). Here are some screenshots from the CodePlex. All the credits go to Renaud Comte. Cool and great job!

Tree1

Tree4

MultipleTV

SharePoint Polling WebPart

I just found a great Polling WebPart from Phil Wicklund. You can find it in CodePlex or in his personal site to check for working examples, screenshots etc. It works great in my last project. There are some restrictions (in current release), like the poll submitter can submit twice/ more and max 5 poll questions / answers. But it can be customized according to our requirements. Phil has given the source code too. Just download it from CodePlex. In order to use it, just use the stsadm.exe command tool (read this tutorial by liedong). All the credit goes to Phil Wicklund. Great Job!

Here are some screenshots taken from Phil's website.