public IActionResult AddStudent(Student S, IFormFile Cv) { string WwwRoot = _ENV.WebRootPath; string FTPpath = WwwRoot + "/WebData/Cv"; string UniqueName = Guid.NewGuid().ToString(); string FileExtension = Path.GetExtension(Cv.FileName); FileStream Fs = new FileStream(FTPpath + UniqueName + FileExtension, FileMode.Create); Cv.CopyTo(Fs); Fs.Close(); S.Cv = "/WebData/Cv" + UniqueName + FileExtension; _ORM.Add(S); _ORM.SaveChanges(); string APIURL = "http://bulksms.com.pk/api/sms.php?username=923316125207&password=9178&sender=BrandName&mobile=923349931854&message= Welcome to our website."; using (var APIClient = new HttpClient()) { Task <HttpResponseMessage> RM = APIClient.GetAsync(APIURL); Task <string> FinalRespone = RM.Result.Content.ReadAsStringAsync(); } ModelState.Clear(); MailMessage Obj = new MailMessage(); Obj.From = new MailAddress("*****@*****.**"); Obj.To.Add(new MailAddress(S.Email)); Obj.Subject = "Welcome to theta Solution:"; Obj.Body = "Dear" + S.Name + "<br ><br >" + "Thanks for registration with Theta Solution"; Obj.IsBodyHtml = true; if (!string.IsNullOrEmpty(S.Cv)) { Obj.Attachments.Add(new Attachment(_ENV.WebRootPath + S.Cv)); } SmtpClient SMTP = new SmtpClient(); SMTP.Host = "*****@*****.**"; SMTP.Port = 587; SMTP.EnableSsl = true; SMTP.Credentials = new System.Net.NetworkCredential("*****@*****.**", "programer"); try { SMTP.Send(Obj); } catch (Exception ex) { ViewBag.Message = "Mail has sent successfully"; } ViewBag.Message = "New student has added to list"; return(View()); }
public IActionResult AddStudent(Student S, IFormFile Cv) { string WwwRoot = _ENV.WebRootPath; string FTPpath = WwwRoot + "/WebData/Cv"; string UniqueName = Guid.NewGuid().ToString(); string FileExtension = Path.GetExtension(Cv.FileName); FileStream Fs = new FileStream(FTPpath + UniqueName + FileExtension, FileMode.Create); Cv.CopyTo(Fs); Fs.Close(); S.Cv = "/WebData/Cv" + UniqueName + FileExtension; _ORM.Add(S); _ORM.SaveChanges(); ModelState.Clear(); MailMessage oEmail = new MailMessage(); oEmail.From = new MailAddress("*****@*****.**"); oEmail.To.Add(new MailAddress(S.Email)); //oEmail.CC.Add(new MailAddress("*****@*****.**")); oEmail.Subject = "Thanks for Regisration"; oEmail.Body = "Dear " + S.Name + ",<br><br>" + "Thanks for registering with ABC, We are glad to have you in our system." + "<br><br>" + "<b>Regards</b>,<br>ABC Team"; oEmail.IsBodyHtml = true; if (!string.IsNullOrEmpty(S.Cv)) { oEmail.Attachments.Add(new Attachment(WwwRoot + S.Cv)); } SmtpClient oSMTP = new SmtpClient(); oSMTP.Host = "smtp.gmail.com"; oSMTP.Port = 465; oSMTP.EnableSsl = true; oSMTP.Credentials = new System.Net.NetworkCredential("*****@*****.**", "programer"); try { oSMTP.Send(oEmail); } catch (Exception ex) { } // ViewBag.Message = "Student Record has been added"; return(View()); }