0

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);
}
Chandan
  • 217
  • 1
  • 3
  • 17
  • Can you find in debugger what is the result of `Server.MapPath(Certpath) + "MyPdf.pdf"`? I believe you have to separate the two with a slash (\\) – Martin Jan 28 '16 at 05:14
  • Hi Martin, The debugger shows this result : C:\xyz\abcTest\Dev\PL\Documents\MyPdf.pdf with Count = 1 . – Chandan Jan 28 '16 at 06:51
  • could you please confirm which line of code it is breaking (or becoming unresponsive)? – Martin Jan 28 '16 at 06:57
  • martin Here : new MailSender().SendMail((int)eMailType.GenerateMail, null, pramAttachment); – Chandan Jan 28 '16 at 07:19
  • Is `SendMail` a method that you created? If so, can you include the code for that as well in the question? – Martin Jan 28 '16 at 10:27

2 Answers2

0

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?

Woland
  • 2,881
  • 2
  • 20
  • 33
0

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 .

Chandan
  • 217
  • 1
  • 3
  • 17