1

I am trying to write an mailsender in C# for sharepoint but each time I start it I get this error message that tells me that it doesn't have permission.

I tried do give it permission at AppManifest.xml but I don't know which... I tried all but nothing seams to help.

my code:

private void SendEmail( ClientContext clientContext )
{
    User sendToUser = clientContext.Web.EnsureUser( "mymail@mail.com" );
    clientContext.Load( sendToUser );
    clientContext.ExecuteQuery();

    string email = Microsoft.SharePoint.Client.Utilities.Utility.GetCurrentUserEmailAddresses( clientContext ).Value;

    Microsoft.SharePoint.Client.Utilities.EmailProperties properties = new Microsoft.SharePoint.Client.Utilities.EmailProperties();
    properties.To = new string[] { sendToUser.Email };
    properties.Subject = "subject";
    properties.Body = "body";

    Microsoft.SharePoint.Client.Utilities.Utility.SendEmail( clientContext, properties );

    clientContext.ExecuteQuery();
}

Dos someone have a tip for me what could be wrong.

rashfmnb
  • 9,959
  • 4
  • 33
  • 44

2 Answers2

0

It doesn't feel right. You should not be able to send email using server resources from client side code.

for resolution please see https://sharepoint.stackexchange.com/questions/97354/send-email-from-csom

Community
  • 1
  • 1
Salman Siddiqui
  • 340
  • 3
  • 13
0

Give the sender (CurrentUser)the permission of "Manage Alerts"