Click here to Skip to main content
15,893,663 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I am new in ASP.Net. I need your favour Please help me. See my Code..
If My First job is finished then exit from btn_ok code behind and update to ASP.NET screen, but at the same time Job 2 must working (Bulk Email is processing)
C#
protected void btn_ok(object sender, EventArgs e)
  {

  try

    {

     //**Job 1:**

     CommonCls com = new CommonCls();
     com.SaveRecord(**Parameter Values**);

     //Note :after save this, it must exit from this function and update Message to web Application Screen

    //**Job 2**
     SendEmail();
    }
   catch (Exception ex)
   { }

   }
Posted
Comments
Kats2512 8-Oct-15 9:19am    
and the code for SendEmail() ? can you please provide that piece as there could be an issue in that snippet of code.
Victor Ebe 8-Oct-15 9:26am    
EmailDAL em = new EmailDAL();
string PTName = Convert.ToString(dt1.Rows[0]["PatientName"]);
string PTEmail = Convert.ToString(dt1.Rows[0]["PatientEmail"]);
string PName = Convert.ToString(dt1.Rows[0]["ReceiverName"]);
string PEmail = Convert.ToString(dt1.Rows[0]["ReceiverEmail"]);
string GPName = Convert.ToString(dt1.Rows[0]["SenderName"]);
string GPEmail = Convert.ToString(dt1.Rows[0]["SenderEmail"]);
string PTCode = Convert.ToString(dt1.Rows[0]["PatientCode"]);
string GPPhone = Convert.ToString(dt1.Rows[0]["GPPhone"]);
DateTime dt11 = Convert.ToDateTime(e.OldStart);
string Stime = " from " + String.Format("{0:ddd, MMM d, yyyy hh:mm tt}", dt11);
DateTime dt12 = Convert.ToDateTime(e.NewStart);
Stime = Stime + " to " + String.Format("{0:ddd, MMM d, yyyy hh:mm tt}", dt12);
string axolbl = "<br><img style='width: 160px;' src='http://*******.com/images/logo.jpg'>";
try
{
em.SendEmail(PTEmail, "Appointment Rescheduled ", "Dear " + PTName + "<br>      Appointment with " + PName + " referred by " + GPName + " has been rescheduled " + Stime + ". <br> with Regards <br> " + GPName + "" + axolbl);
}
catch (Exception ex) { logger.Error(ex.ToString()); }
try
{
em.SendEmail(PEmail, "Appointment Rescheduled ", "Dear " + PName + "<br>      Appointment for " + PTName + "(" + PTCode + ") referred by " + GPName + " has been rescheduled " + Stime + ". <br> with Regards <br> " + GPName + "" + axolbl);
}
catch (Exception ex) { logger.Error(ex.ToString()); }
try
{
em.SendEmail(GPEmail, "Appointment Rescheduled ", "Dear " + GPName + "<br>      Appointment for " + PTName + "(" + PTCode + ") with " + PName + " has been rescheduled " + Stime + ". <br> with Regards <br> AXO Referral Engine" + axolbl);
}
catch (Exception ex) { logger.Error(ex.ToString()); }
try
{
em.SendEmail(ConfigurationManager.AppSettings["adminMail"], "Appointment Rescheduled ", " Appointment for " + PTName + "(" + PTCode + ") with " + PName + " referred by " + GPName + " on " + Stime + " has been rescheduled. <br> <br>Regards <br> " + axolbl);
}
catch (Exception ex) { logger.Error(ex.ToString()); }
Victor Ebe 8-Oct-15 9:27am    
public class EmailDAL
{

internal string SMTP = ConfigurationManager.AppSettings["smtpServer"];
internal string MailAddress = ConfigurationManager.AppSettings["smtpUser"];
internal string Pwd = ConfigurationManager.AppSettings["smtpPass"];
internal int Port = Convert.ToInt16(ConfigurationManager.AppSettings["smtpPort"]);
internal bool ssl = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableSsl"]);

public string SendEmail(string toMail, string mailSubject, string Message)
{

SmtpClient SmtpServer = new SmtpClient(SMTP);
var mail = new MailMessage();
mail.From = new MailAddress(MailAddress);
mail.To.Add(toMail);
mail.Subject = mailSubject;
mail.IsBodyHtml = true;
mail.Body = "<p style='line-height: 30px;'>" + Message + "</p>";
SmtpServer.Port = Port;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential(MailAddress, Pwd);
SmtpServer.EnableSsl = ssl;
try
{
SmtpServer.Send(mail);
return "Send Sucessfully";
}
catch (Exception ex)
{
return ex.Message.ToString();
}
}
}

Sounds like you want to run the SendEmail method as a background task:
How to run Background Tasks in ASP.NET | Scott Hanselman[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900