Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [HttpPost]
- public async Task<ActionResult> Index2(LigneCommandeT LigneCommandeT , string submit)
- {
- switch (submit)
- {
- case "Ajouter" :
- context.LigneCde.Add(LigneCommandeT);
- context.SaveChanges();
- return RedirectToAction("Index2");
- break;
- case "Valider" :
- // var message = EMailTemplate("Welcome");
- await MessageServices.SendEmailAsync("sabrinenaceur25@gmail.com", "Welcome!", "message");
- return RedirectToAction("Index3");
- break;
- default :
- return RedirectToAction("Index2");
- break;
- }
- }
- public async static Task SendEmailAsync(string email , string subject ,string message)
- {
- try
- {
- var _email="sabrinenaceur25@gmail.com"; // sender's email
- var _epass = ConfigurationManager.AppSettings["EmailPassword"]; // get our password from web.config
- var _dispName = "Sabrine";
- MailMessage MyMessage = new MailMessage();
- MyMessage.To.Add(email);
- MyMessage.From = new MailAddress(_email,_dispName);
- MyMessage.Subject = subject ;
- MyMessage.Body = message ;
- MyMessage.IsBodyHtml = true;
- using(SmtpClient smtp = new SmtpClient())
- {
- smtp.EnableSsl =true ;
- smtp.Host = "smtp.live.com";
- smtp.Port = 587 ;
- smtp.UseDefaultCredentials = false ;
- smtp.Credentials = new NetworkCredential(_email,_epass);
- smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
- smtp.SendCompleted += (s,e) => {smtp.Dispose();} ;
- await smtp.SendMailAsync(MyMessage);
- }
- }
- catch(Exception ex)
- {
- throw ex ;
- }
- <appSettings>
- <add key="webpages:Version" value="3.0.0.0" />
- <add key="webpages:Enabled" value="false" />
- <add key="ClientValidationEnabled" value="true" />
- <add key="UnobtrusiveJavaScriptEnabled" value="true" />
- <add key="EmailPassword" value="" />
- </appSettings>
- <system.net>
- <mailSettings>
- <smtp deliveryMethod="Network">
- <network enableSsl="true" host="smtp.live.com" port="587" defaultCredentials="false" userName="sabrinenaceur25@gmail.com" password=""/>
- </smtp>
- </mailSettings>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement