I am storing the email of the user in session
var v = //login query
Session["LoggedUserEmail"] = v.email.ToString();
Then after login I want to send an email to the current logged in user and for that purpose I am passing Session["LoggedUserEmail"] in Msg.To.Add but its not working.
This is what I am doing
public void Execute(IJobExecutionContext context)
{
System.Net.Mail.MailMessage Msg = new System.Net.Mail.MailMessage();
Msg.From = new MailAddress("abc@gmail.com");
Msg.To.Add(Session["LoggedUserEmail"].ToString());
Msg.Subject = "Email";
Msg.Body = "Hi";
Msg.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential("abc@gmail.com", "xxxxxxx");
smtp.EnableSsl = true;
smtp.Send(Msg);
Response.Write("Email Sent");
}
我做错了吗?如果有,那么还有其他方法可以完成工作吗?
我正在使用quartz.net并在我的mvc控制器中实现了IJob接口。