Quantcast
Channel: Microsoft Online: SharePoint Online forum
Viewing all articles
Browse latest Browse all 10096

Email through Event receiver in SharePoint Online

$
0
0

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


Viewing all articles
Browse latest Browse all 10096

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>