public async Task <IActionResult> AddNewSong(SongModel songModel, bool isSuccess = false, int songId = 0) { var userId = _userManager.GetUserId(this.HttpContext.User); var user = await _userManager.GetUserAsync(HttpContext.User); songModel.UserId = userId; if (ModelState.IsValid) { if (songModel.CoverPhoto != null) { string folder = "songs/cover/"; songModel.CoverImageUrl = await UploadImage(folder, songModel.CoverPhoto); } if (songModel.SongFile != null) { string folder = "songs/songfiles/"; songModel.SongUrl = await UploadImage(folder, songModel.SongFile); } ViewBag.IsSuccess = isSuccess; ViewBag.SongId = songId; int id = await _songRepository.AddNewSong(songModel); if (id > 0) { //return RedirectToAction(nameof(AddNewSong), new { isSuccess = true, songId = id }); TempData["Alert"] = true; // Mail sending //#region Mail MailMessage msg = new MailMessage // instance Mail sender service { From = new MailAddress("*****@*****.**"), // Server Email Address }; var subscribers = _songRepository.GetSubscriber(userId); foreach (var subscriber in subscribers) { msg.To.Add(subscriber.SubscribeUserEmail); // receiver Email msg.Subject = "EarTube - New Song Upload"; msg.Body = $"Hello {subscriber.SubscribeUserEmail}, {user.FirstName}-{user.LastName} as added a new song. Go check it out"; // Message Body } SmtpClient client = new SmtpClient { Host = "smtp.gmail.com" }; NetworkCredential credential = new NetworkCredential { // Server Email credentisal UserName = "******", Password = "******" }; client.Credentials = credential; client.EnableSsl = true; client.Port = 587; client.Send(msg); ViewBag.Success = $"Email has been sent successfully to your subscriber"; return(RedirectToAction(nameof(GetAllSongs), new { songId = id })); } } return(View()); }