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.
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.
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"] = "firstname.lastname@example.org"; item["Message"] = "message"; item.Update();
See this blog entry by Peter Vogel: http://visualstudiomagazine.com/blogs/tool-tracker/2012/04/send-an-email-in-office-365.aspx