Skip to content
Loading
  • 0
    Rajkiran,
    right now im working on the same code. but im getting error at :
    1. StringDictionary headers = new StringDictionary();
    2. headers.Add("fromom);
    3. headers.Add("to);
    4. headers.Add("cc);
    5. headers.Add("bcc);
    6. headers.Add("subjectbject);
    7. SPUtility.SendEmail(currentWeb, headers, bodyText);
     Add method.
    could you please tell how to resolve this. 
    0
  • Rajkiran Swain
    0
    Ok. Then please send me the error message plus your code .
    0
  • Rajkiran Swain
    0
    Event receivers run within the context of the user, so you will probably not have the proper permissions to send mail. Try to wrap the functionality in the SendMail function inside a RunwithElevatedPrivileges block
    0
  • Rajkiran Swain
    0
    1. public override void ItemAdded(SPItemEventProperties properties)  
    2. {  
    3.     string url = properties.WebUrl;  
    4.   
    5.     SPSecurity.RunWithElevatedPrivileges(delegate()  
    6.     {  
    7.         using (SPSite site = new SPSite(url))  
    8.         {  
    9.             using (SPWeb web = site.OpenWeb())  
    10.             {  
    11.                 // [email protected] is obviously replaced with a real working email  
    12.                 SendMail(web, "[email protected]", "[email protected]", "Test", "Some text here", "", "");  
    13.             }  
    14.         }  
    15.     });  
    16. }  
    do like this . 
    0
  • 0
    okay..please check..this is the code im trying:
     
    using System;
    using System.Security.Permissions;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Utilities;
    using Microsoft.SharePoint.Workflow;
    using Microsoft.SharePoint;
    using System.Net.Mail;
    namespace SendEmail.SenEmailEvent
    {
    ///
    /// List Item Events
    ///
    public class SenEmailEvent : SPItemEventReceiver
    {
    ///
    /// An item was added.
    ///
    public override void ItemAdded(SPItemEventProperties properties)
    {
    base.ItemAdded(properties);
    string subject = string.Empty;
    string from = string.Empty;
    string to = string.Empty;
    string bodyText = string.Empty;
    string cc = string.Empty;
    string bcc = string.Empty;
    if (properties.ListTitle != "PhotoGallery")
    { return; }
    else
    {
    using (SPWeb currentWeb = new SPSite(properties.WebUrl).OpenWeb())
    {
    SPList list = currentWeb.Lists.TryGetList("PhotoGallery");
    if (list == null)
    return;
    SPListItem thisItem = properties.ListItem;
    //Set email subject
    subject = "New Item has added: " + thisItem["EventName"];
    // Set from address
    //get user or group
    SPFieldUserValue userOrGroup = new SPFieldUserValue(currentWeb, thisItem["RootSite Owners"].ToString());
    //Check is it user or group.
    if (userOrGroup.User == null)
    {
    //If group add users email Id
    SPGroup oGroup = currentWeb.Site.RootWeb.SiteGroups["RootSite Owners"];
    foreach (SPUser user in oGroup.Users)
    {
    to += user.Email + ",";
    }
    }
    else
    {
    //if user then add user email id
    to = userOrGroup.User.Email;
    }
    //Set mail body
    string header = "Dear Sir," + "
    " + "
    ";
    string body = " You body text. " + "
    " + " " + "
    ";
    string footer = "Thanks & regards," + "
    " + "\n Listen2Customer";
    bodyText = header + body + footer;
    StringDictionary headers = new StringDictionary();
    headers.Add();
    headers.Add(to);
    headers.Add(cc);
    headers.Add(bcc);
    headers.Add(subject);
    StringDictionary.SendEmail(currentWeb, headers, bodyText);
    }
    }
    }
    }
    }
     
    error message:  SendEmail.stringDictionary does not contain a definition for  "Add" or No Extention method for "Add"
    0
  • Rajkiran Swain
    0
    try this link.
     
     
    https://social.msdn.microsoft.com/Forums/office/en-US/f691db16-0a7a-43cc-b897-5517cce3b2b9/sending-emails-from-event-receiver?forum=sharepointdevelopmentprevious
     
    https://stackoverflow.com/questions/10242790/cannot-send-mail-in-sharepoint-using-event-receiver
     
    http://techiescode.blogspot.in/2013/10/send-email-from-sharepoint-event.html 
    0
  • 0
    Dear Rajkiran,
    My task is i have a picture library with two columns 1. EventName 2.Department
    whenever a user add an item in that library.
    the event reciever should shoot a mail to a specific group in sharepoint.
     
    can you please modify my code. and send a proper code to me for this task.
    :)
    Thank You 
    0
  • 0
    Add a APproval or publishing work flow  for the library and check create the workflow when add an item and add a group in approvers stage. It will send a mail to the particular group
    0
  • Rajkiran Swain
    0
    It's better if you use Workflow instead of Event Receiver .
    0