how to send email to a user in office 365 using c# code. I am not able to find it, as what I exactly want is to, when a user with read permissions log in, send an email to person who has contribute permission. Only 1 person will have contribute permissions in site collection.

2 Answers 2


In SharePoint Online(o365) you cannot send email through Sandboxed Code .The best way to send email will be to use SharePoint Designer workflows "Send Email" action.

[Update]: Looking to your scenario , ie notify the Contribute permission user whenever user with read permission logs in. You can create a dummy hidden list, break inheritance of that list and provide the "Viewers"(or whatever be the group name for Read users) Contributre permission only in that list.Whenever read user logs in write a ECMA script for adding the logged in details of the user into that list. Attach a List WF to that list which will send email to "Contributors" group with details like logged in user's name , time of login etc.

  • alerts ? if no email ? Commented Mar 31, 2014 at 14:27
  • I have updated answer to suit your scenario. You can think over it and start with the logic i updated.
    – Unnie
    Commented Mar 31, 2014 at 19:01

As Unnie stated, since Sandboxed Solutions do not have access to SPUtility.SendEmail, you cannot use c# to send emails. What you will have to do is, as Unnie stated, use a designer workflow's "Send Email" action. You can create a list called "SendEmail", and have the workflow run when an item is added to that list. You can then use C# to add items to that list.

SPWeb mySite = SPContext.Current.Web; 
SPListItemCollection  listItems = mySite.Lists["SendMail"].Items; 
SPListItem item =  listItems.Add(); 
item["Subject"] =  "subject"; 
item["To"] =  "[email protected]"; 
item["Message"] =  "message"; 

See this blog entry by Peter Vogel: http://visualstudiomagazine.com/blogs/tool-tracker/2012/04/send-an-email-in-office-365.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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