Advertisement
Guest User

Untitled

a guest
Apr 24th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. [HttpPost]
  2. public async Task<ActionResult> Index2(LigneCommandeT LigneCommandeT , string submit)
  3. {
  4. switch (submit)
  5. {
  6. case "Ajouter" :
  7. context.LigneCde.Add(LigneCommandeT);
  8. context.SaveChanges();
  9. return RedirectToAction("Index2");
  10. break;
  11. case "Valider" :
  12. // var message = EMailTemplate("Welcome");
  13. await MessageServices.SendEmailAsync("sabrinenaceur25@gmail.com", "Welcome!", "message");
  14.  
  15. return RedirectToAction("Index3");
  16. break;
  17. default :
  18. return RedirectToAction("Index2");
  19. break;
  20. }
  21. }
  22.  
  23. public async static Task SendEmailAsync(string email , string subject ,string message)
  24. {
  25. try
  26. {
  27. var _email="sabrinenaceur25@gmail.com"; // sender's email
  28. var _epass = ConfigurationManager.AppSettings["EmailPassword"]; // get our password from web.config
  29. var _dispName = "Sabrine";
  30. MailMessage MyMessage = new MailMessage();
  31. MyMessage.To.Add(email);
  32. MyMessage.From = new MailAddress(_email,_dispName);
  33. MyMessage.Subject = subject ;
  34. MyMessage.Body = message ;
  35. MyMessage.IsBodyHtml = true;
  36.  
  37. using(SmtpClient smtp = new SmtpClient())
  38. {
  39. smtp.EnableSsl =true ;
  40. smtp.Host = "smtp.live.com";
  41. smtp.Port = 587 ;
  42. smtp.UseDefaultCredentials = false ;
  43. smtp.Credentials = new NetworkCredential(_email,_epass);
  44. smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
  45. smtp.SendCompleted += (s,e) => {smtp.Dispose();} ;
  46. await smtp.SendMailAsync(MyMessage);
  47.  
  48.  
  49. }
  50. }
  51. catch(Exception ex)
  52. {
  53. throw ex ;
  54. }
  55.  
  56. <appSettings>
  57. <add key="webpages:Version" value="3.0.0.0" />
  58. <add key="webpages:Enabled" value="false" />
  59. <add key="ClientValidationEnabled" value="true" />
  60. <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  61. <add key="EmailPassword" value="" />
  62. </appSettings>
  63.  
  64. <system.net>
  65. <mailSettings>
  66. <smtp deliveryMethod="Network">
  67. <network enableSsl="true" host="smtp.live.com" port="587" defaultCredentials="false" userName="sabrinenaceur25@gmail.com" password=""/>
  68. </smtp>
  69. </mailSettings>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement