Mails not going through SendEmail Activity

Finally i got the time to write after such a long time. Many times i have seen people writing on several forums that mails are not going through SendEmail activity albeit all the email settings are perfect. You will find this activity in SharePoint Designer as well as Visual Studio. I faced this problem in Visual Studio and the strangest thing was that the workflow was fine in the beginning and after 1 month, the mails just stopped going. Lets see how i made this work.

One day, in office, lot of people came to me complaining that their documents got approved but they did not get any mail. I asked everyone and not even a single person got the approval mail. Whenever this happens, the first thing is to check the workflow history. To check the workflow history, just click the workflow column (which show the status of the item) and you will see the workflow history just below. When i saw it then there was one error line saying "The email message cannot be sent. Please check your outgoing mail server settings".

I was sure that my outgoing mail settings were perfect as all the mails in other workflows were going. I designed a State Machine workflow in which i used "SendEmail" activity. I understood that the problem is in this activity only. There are two ways to configure the properties of a SendEmail activity :

1) By creating separate variables for "To", "From", "Subject" and "Body" tags in the properties window of the Designer page. That is, you define the variables by clicking that ellipse on the right hand side. And then use that variable in the code editor. For eg : If you defined variable of "To" in the Properties window as "SendEmail_To" then write the code : SendEmail_To = @"myemail@domain.com".

2) The second option is to use the properties of the SendEmail activity directly in the code editor. For eg : SendEmail.To = @"myemail@domain.com". In this case, we do not bind the variables in the properties window as we do in the first case.

Now i was following the second method and my mails just stopped going after one month as mentioned before. The only solution to this problem was to switch to first method. I tried it just like that, without any reason and damn........... it worked. Yes, after that my mails started going and its been a year now, i did not face any problem.

I still do not have the explanation for why the second method did not work. Really strange. Later on, many people wrote this issue on the MSDN Forums and i suggested them this solution and it helped them a lot. So i thought of writing this so that more people will be free from this hair pulling issue.
Hope you liked reading it.

Source:sharepointissues.blogspot.com

0 nhận xét:

Post a Comment

thanks comment