Hi,
I am creating an event receiver for custom list which will send email to users in sharepoint online.
I am using the following code to send email through event receivers in sharepoint.
MailMessage mMailMessage = new MailMessage();
mMailMessage.From = new MailAddress("xxx@onmicrosoft.com");
mMailMessage.To.Add(new MailAddress("yyy@y.com));
mMailMessage.Subject = "subject1";
mMailMessage.Body = "just a body";
mMailMessage.IsBodyHtml = true;
SmtpClient client = new SmtpClient("smtp.office365.com", 587)
{
Credentials = new NetworkCredential("xxx@onmicrosoft.com", "****"),
EnableSsl = true,
UseDefaultCredentials = false,
};
client.Send(mMailMessage);
NOTE: I am using MailMessage() because it is in the sandbox solution.
However I am facing the following error :
Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
It may be because I am trying to use SMTP server of sharepoint Online,However I am not able to connect it.
Can anybody help me and can advice how to send email programmatically from sharePoint online ?
Thanks
Jhalak