You can also create a event handler attached to your list.
In event handler, u can just send emails and customize code.
u can send emails using SPUtility.SendEmail also but i avoided it because of limitations.
I have provided code for sending email via gmail account.. this also has limitations...
I have provided my sample code below...
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
if (properties.Web != null && properties.Web.Groups != null)
{
SPGroupCollection groups = properties.Web.Groups;
for (int countGroups = 0; countGroups < groups.Count; countGroups++)
{
SPGroup group = groups[countGroups];
if (group != null)
{
string subject = string.Empty;
string htmlBody = string.Empty;
SPUserCollection groupUsers = group.Users;
if (groupUsers != null && groupUsers.Count > 0)
{
if (groupUsers.Count <= Constants.EmailSettings.MaxUsers)
{
foreach (SPUser user in groupUsers)
{
if (!string.IsNullOrEmpty(user.Email))
{
SendMail(user.Email);
// SPUtility.SendEmail(properties.Web, false, false, user.Email, subject, htmlBody);
}
}
}
else
{
int usersCount = groupUsers.Count;
int mul = 1;
for (mul = 1; mul <= (groupUsers.Count % Constants.EmailSettings.MaxUsers) + 1; mul++)
{
for (int countUser = Constants.EmailSettings.MaxUsers * (mul - 1); countUser < Constants.EmailSettings.MaxUsers * mul; countUser++)
{
if (countUser < groupUsers.Count && countUser < Constants.EmailSettings.MaxUsers * mul)
{
SPUser user = groupUsers[countUser];
if (!string.IsNullOrEmpty(user.Email))
{
SendMail(user.Email);
//SPUtility.SendEmail(properties.Web, false, false, user.Email, subject, htmlBody);
}
}
else
{
break;
}
}
}
}
}
}
}
}
}
private void SendMail(string toMailId)
{
string from = "abc@gmail.com"; //Replace this with your own correct Gmail Address
string to = toMailId; //Replace this with the Email Address to whom you want to send the mail
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add(to);
mail.From = new MailAddress(from, "vikas mehta", System.Text.Encoding.UTF8);
mail.Subject = "This is a test mail";
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = "This is Email Body Text";
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.High;
SmtpClient client = new SmtpClient();
//Add the Creddentials- use your own email id and password
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(from, "Password");
client.Port = 587; // Gmail works on this port<o:p />
client.Host = "smtp.gmail.com";
client.EnableSsl = true; //Gmail works on Server Secured Layer
try
{
ServicePointManager.ServerCertificateValidationCallback =
delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
};
client.Send(mail);
}
catch (Exception ex)
{
Exception ex2 = ex;
string errorMessage = string.Empty;
while (ex2 != null)
{
errorMessage += ex2.ToString();
ex2 = ex2.InnerException;
}
HttpContext.Current.Response.Write(errorMessage);
} // end try
}