0

My machine: Win7 32bit, .net 4

I have a console program based on .net 4 that generate 3 excel files and send them one by one through SMTP Server.

When I double click the exe or run in cmd, it runs correctly and sent 3 emails with these 3 excel files.

But when I put the exe in the Task Scheduler, and click "Run". Only the first email was sent and the other 2 emails were somehow can't be sent.

Any idea?

4
  • I would check the user account that is used by Task Scheduler. It will probably not help as you can send one file, but it is worth the try. Commented Oct 15, 2012 at 7:45
  • The account is in the group of administrator. Commented Oct 15, 2012 at 8:29
  • You should add some logging into the program and see if you get an exception when the program tries to send the second email? Commented Oct 15, 2012 at 13:47
  • Hi Peter~I've run the program in debug mode and everything is ok. But it doesn't in the task scheduler. Commented Oct 16, 2012 at 1:58

2 Answers 2

4

To really know what is going on when the program is run by the Task Scheduler you can put Trace statements at vital steps in your code such as:

Trace.WriteLine("Start creating mail object");

and

Trace.WriteLine(string.Format("Exception occured: {0}\r\n{1}", ex.Message, ex.StackTrace);

Don't forget to put a Trace.WriteLine inside your exception handler so you know if something goes wrong.

You take control over where these statements are written by configuring listeners inside your .config file.

The following example adds an EventLogTraceListener object named myListener to the Trace.Listeners collection. The initializeData parameter specifies the name of the event log source that is to be passed to the EventLogTraceListener(String) constructor.

<configuration>
  <system.diagnostics>
    <trace autoflush="false" indentsize="4">
      <listeners>
        <add name="myListener"
          type="System.Diagnostics.EventLogTraceListener"
          initializeData="TraceListenerLog" />
      </listeners>
    </trace>
  </system.diagnostics>
</configuration>

You can open the EventViewer by going to Start > eventvwr

Hope this helps you to figure out what the problem is because at this point it's anyone's guess.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks Peter. But after I add Trace.WriteLine in my codes. I found NO error or exception in the log file. The program just ran correctly.
So the program sends the mails to the SMTP server without error but somehow the SMTP server does not deliver 2 out of 3 mails?
That's what I thought. But when I check the SMTP Sever, there's only the first email in the sent list.
Have you added logging around the code that sends the mail? Are you sure it executes three times?
Yes, I did. What I saw is the successful message between the code, like "Begin send..." and "Email sent". Is there any possibility that the problem lies in the time out or session lost?
|
0

Problem: Code a .net C# Console Application to upload documents from a share drive to SharePoint document library. When logged in as Service Acct, no issues were found while executing, the files transfered into SP document library without issues. However, executing via Task Scheduler ran into "system.io.directorynotfoundexception...." error. Also note using personal account I had no issues executing the code while logged in on the server or via Task Scheduler executing the .exe using my personal account.

Analysis: When Service Acct. is logged in the mapped drive in the code was accessible. However Task scheduler could not read the mapped drive (namely s:\xxxxx Reports\).

Resolution: Noted that files accessed was from a EMC VNX Windows File Sharing. Changed the consoleapplication code referencing the document location to the following path \server.com\vnxcifs01\Saved_xxxx_Report_Outputs\xxxxxxxxxxx Scheduled Reports. After this change Rebuilt the exe and the Task Scheduler worked like a charm.

I hope this helps some one working on a similar envrionment.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.