Why email is not sending even if the path is working

99 Views Asked by At

This is a piece of code for genrating mail which works until I didnt attach path as a parameter . the thing is if I attach the path it didnt throw any error(no logs). Just the page started being unresponsive,and debugger not even jump to next line. any help wil help me to understand my mistake . Thanks

public ActionResult Mailsending(string list)
      {
        try
        {
            string strIdeas = string.Empty;
            string Certpath =  System.Configuration.ConfigurationManager.AppSettings["UploadPath"];
            List<int> list = new List<int>();
            List<string> pramAttachment = new List<string>();              
            pramAttachment.Add(Server.MapPath(Certpath) + "MyPdf.pdf"); ///Path of the generated pdf.
            Submitidlist = new CommonBL().GetSubmiidListForGenerateMail();

            new CommonBL().UpdateIsGenerateStatus(ideaidlist, UserID);

            foreach (var item in ideaidlist)
            {
                strIdeas = strIdeas + item.ToString() + ",";
            }
            GenerateMyPDF(list); //Here pdf is generating
         
            string path = GenerateMail(strIdeas.TrimEnd(','));

            if (path != string.Empty)
            {
                new CommonBL().AddGenerateImagePath(path, UserId);
                new MailSender().SendMail((int)eMailType.GenerateMail, null, pramAttachment); // here path is added as parameter,and after this debugger not jump out of this scope.
                
            }               
            return Json("Mail generated Successfully."); ///no message showing
            
        }
        catch (Exception ex)
        {
            return Json("Error");
        }
    }

Edit :

public class MailSender : IDisposable
{
  public bool SendMail(short mailId, List<KeyValuePair<string, string>> parameters, List<string> attachmentsPath = null);
}
2

There are 2 best solutions below

0
On BEST ANSWER

adding a point which apparently is also an answer of this question, is : After debugging whole code, I found that my smtp server is not allowing to send me a mail, so even if the above code is right, it shows processing. So if anyone is working with above code will work fine.

An update : Now it works fine after configuring my mail service from control panel. So if any one wants to take reference from this can go ahead . the code is fine .

1
On

Possibly still leaving lock on the generated PDF, so MailSender is not able to access it due to that exclusive lock. Can you send emails with files previously generated?