It's working fine in my local and in the Test Server. But upon deploying this in Production server.
I'm getting the Internal Server Error 500 with this function.
All the function works fine except for this one.
Function to call the sending of email in the view:
function ProcessSendingEmail(NextMRB, to, originator, owner, probDesc, hold_day, MRB_Type) { $.ajax({ type: "POST", url: '@Url.Action("SendMailToFutureHold", "MRB")', data: { MRBNumber: NextMRB, MailTo: to, Originator: originator, Owner: owner, ProbDesc: probDesc, hold_days: hold_day, mrb_type: MRB_Type}, success: function (data) { console.log("Email Sent"); }, error: function (data) { console.log("Email Not Sent"); } }); } Controller
[HttpPost] public ActionResult SendMailToFutureHold(string MRBNumber, string MailTo, string Originator, string Owner, string ProbDesc, string hold_days, string mrb_type) { MailId = Originator + "@domain.com"; DataTable dt = MRB.GetDataForAttachmentForFH(MRBNumber, MailTo, mrb_type); byte[] bytes; //dt.Columns.RemoveAt(dt.Columns.Count - 1); dt.TableName = "MRB_Future_Hold_List_" + MRBNumber; Response.ClearContent(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment;filename = MRB_Future_Hold_List_" + MRBNumber + ".csv"); Response.ContentType = "text/csv"; Response.Charset = ""; using (StringWriter sw = new StringWriter()) { int iColCount = dt.Columns.Count; int iRowcount = dt.Rows.Count; if (iRowcount != 0) { for (int i = 0; i < iColCount; i++) { sw.Write(dt.Columns[i]); if (i < iColCount - 1) { sw.Write(","); } } sw.Write(sw.NewLine); foreach (DataRow dr in dt.Rows) { for (int i = 0; i < iColCount; i++) { if (!Convert.IsDBNull(dr[i])) { sw.Write(dr[i].ToString()); } if (i < iColCount - 1) { sw.Write(","); } } sw.Write(sw.NewLine); } } else { sw.Write("Something went wrong. Please contact [email protected]"); } using (HtmlTextWriter htw = new HtmlTextWriter(sw)) { using (MemoryStream mStream = new MemoryStream(Encoding.ASCII.GetBytes(sw.ToString()))) { string messageBody = "<b>Originator :</b> " + Originator.ToUpper() + "<br> <b>Owner :</b> " + Owner.ToUpper() + "<br> <b>Problem Description :</b> <br>" + ProbDesc.ToUpper() + "<br><br><font> Attached file are the list of lots to put on MRB Hold. </font><br><br>"; bytes = mStream.ToArray(); Mail_Service sndmail = new Mail_Service("mailrelay.domain.com", "[email protected]", MailTo, QA_Contact_Email + "," + MailId + ",[email protected]"); sndmail.Send_Mail("LOTS FOR MRB FUTURE HOLD", messageBody, bytes, MRBNumber); } Response.Flush(); Response.End(); } } return View(); } If anyone can help me. It is much appreciated. Thanks.
return View();.