Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2016
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. private void SendEmail( ClientContext clientContext )
  2. {
  3. User sendToUser = clientContext.Web.EnsureUser( "my.mail@mail.com" );
  4. clientContext.Load(sendToUser);
  5. clientContext.ExecuteQuery();
  6.  
  7. string email = Microsoft.SharePoint.Client.Utilities.Utility.GetCurrentUserEmailAddresses( clientContext ).Value;
  8.  
  9. Microsoft.SharePoint.Client.Utilities.EmailProperties properties = new Microsoft.SharePoint.Client.Utilities.EmailProperties();
  10. properties.To = new string[] { sendToUser.Email };
  11. properties.Subject = "subject";
  12. properties.Body = "body";
  13.  
  14. Microsoft.SharePoint.Client.Utilities.Utility.SendEmail( clientContext, properties );
  15.  
  16. clientContext.ExecuteQuery();
  17. }
  18.  
  19. MailMessage mail = new MailMessage("from@mail.com", "to@mail.com");
  20. SmtpClient client = new SmtpClient();
  21. client.Port = 25;
  22. client.DeliveryMethod = SmtpDeliveryMethod.Network;
  23. client.UseDefaultCredentials = false;
  24. client.Host = "smtp.google.com";
  25. mail.Subject = "this is a test email.";
  26. mail.Body = "this is my test email body";
  27. client.Send(mail);
  28.  
  29. var spContext = SharePointContextProvider.Current.GetSharePointContext(Context);
  30. using (var clientContext = spContext.CreateUserClientContextForSPHost())
  31. {
  32. var emailp = new EmailProperties();
  33. emailp.BCC = new List<string>{"a@mail.com"};
  34. emailp.To = new List<string>{"b@mail.com"};
  35. emailp= "from@mail.com";
  36. emailp.Body = "<b>html</b>";
  37. emailp.Subject = "subject";
  38. Utility.SendEmail(_clientContext, properties);
  39. _clientContext.ExecuteQuery();
  40. }
  41.  
  42. var mail = {
  43. properties: {
  44. __metadata: { 'type': 'SP.Utilities.EmailProperties' },
  45. From: 'from@mail.com',
  46. To: { 'results': ['one@mail.com','two@mail.com'] },
  47. Body: 'some body',
  48. Subject: 'subject'
  49. }
  50. };
  51.  
  52. var getAppWebUrlUrl = decodeURIComponent(utils.getQueryStringParameter("SPAppWebUrl").replace("#", ""));
  53. var urlTemplate = getAppWebUrlUrl + "/_api/SP.Utilities.Utility.SendEmail";
  54. $.ajax({
  55. contentType: 'application/json',
  56. url: urlTemplate,
  57. type: "POST",
  58. data: JSON.stringify(mail),
  59. headers: {
  60. "Accept": "application/json;odata=verbose",
  61. "content-type": "application/json;odata=verbose",
  62. "X-RequestDigest": $("#__REQUESTDIGEST").val()
  63. },
  64. success: function (data) {
  65.  
  66. // code
  67.  
  68. },
  69.  
  70. error: function (err) {
  71.  
  72. // code
  73.  
  74. }
  75. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement