ALTER PROCEDURE [dbo].[GetEmailAdd_Sp] @emplid int AS BEGIN Declare @emplEmail varchar(50) -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; Select emailAdd from HrEmployee where EmplID = @emplid --return @emplEmail END
public ActionResult dailyLog(String txtEmailTo, String txtCC, String txtSubject, String txtBody) { if (!String.IsNullOrEmpty(Session["Employee"] as string)) { int emplid = Convert.ToInt32(Session["Employee"]); String emailFrom = Convert.ToString(DataContext.GetEmailAdd_Sp(emplid).FirstOrDefault()); SmtpClient SmtpServer = new SmtpClient("mail.precisetech.com.pk"); var mail = new MailMessage(); mail.From = new MailAddress(emailFrom); string[] to = txtEmailTo.Split(';'); foreach (string mailTo in to) { mail.To.Add(mailTo); } string[] cc = txtCC.Split(';'); foreach (string copyTo in cc) { MailAddress cCopy = new MailAddress(txtCC); mail.CC.Add(copyTo); } mail.Subject = txtSubject; mail.IsBodyHtml = true; // mail.CC = txtCC; string htmlBody; htmlBody = txtBody; mail.Body = txtBody; SmtpServer.Port = 25; SmtpServer.UseDefaultCredentials = false; SmtpServer.Credentials = new System.Net.NetworkCredential(emailFrom, ""); SmtpServer.EnableSsl = false; try { SmtpServer.Send(mail); ViewBag.Confirmation = "Daily Log Has Been Submitted"; return View(); } catch (Exception ex) { ViewBag.Confirmation = ex.Message; return View(); } }
DataContext.GetEmailAdd_Sp(emplid)
emplid
emailFrom
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)