Sending Email using C# (with HTML body & Attachment )

This article is provide a basic idea how we can send Emails from a C# Windows Application.
Here I have described how we can send mail with Attachment and HTML body.

If we want to send mail then we need to know following things
1. SMTP Server address
2. Port No

Here I have used gmail as a SMTP Server
for gmail account
SMTP Server:
SMTP port : 465 or 587
your account Name:###
your password:###

Continue reading

Converting List to DataTable in C#

There is no built in method for converting list to data table in C#.
So we can implement following method for converting List to DataTable in C#.

 public DataTable ToDataTable(IList data)
            PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(t));
            DataTable table = new DataTable();
            for (int i = 0; i < props.Count; i++)
                PropertyDescriptor prop = props[i];
                table.Columns.Add(prop.Name, prop.PropertyType);
            object[] values = new object[props.Count];
            foreach (t item in data)
                for (int i = 0; i < values.Length; i++)
                    values[i] = props[i].GetValue(item);
            return table;