Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a calender web part - out of box.

I would like to send a notification mail to a particular group members (Always same group), each time I add a new event!! With the Event details like, location, time etc..

How can I get this done? Thank you!!

UPDATE

While scheduling the meeting, where can I select attendees, I didn't get any option to select that.

share|improve this question
    
Do you mean where you select the attendees in the workflow or in the calendar event? –  David Aleu Nov 4 '11 at 13:34
    
@DavidAleu Hi I was trying to select them from calender event itself, How can I select attendees in either way? –  Jithu Nov 7 '11 at 4:35

2 Answers 2

up vote 3 down vote accepted

You could easily get this done using a workflow. Attach the workflow to the events list you use and every time an event is added it will trigger the actions in the workflow.

share|improve this answer
    
Thank you, Dav , However my question is sending mail using workflow is fine. how to select the details of the event, such as Location, Time etc in that mail? –  Jithu Nov 4 '11 at 10:01
1  
In a workflow when you select "send an email", you can edit the text in the email adding your own text and embed item columns from your events list (or from other lists too). Button "Add lookup to Body". –  David Aleu Nov 4 '11 at 10:09
    
Thank you Dav, Got it!! However one more related question, while scheduling an event where can I select the attendees value? I did not see any option to select it!! –  Jithu Nov 4 '11 at 10:17
    
Unfortunately you can't select a person/group column in the workflow. What I usually do is have another column with a calculated field that generates a list of people/groups separated by semicolon to use in the workflow. It probably be a subject for another question though! –  David Aleu Nov 4 '11 at 11:47

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 

    }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.