sent time incorrect

B

bonokoot

Hello,
I wrote this program in C# that accesses a SQL Server database that
runs a stored procedure and sents the results in an email every 30min.
I wrote this as a windows application instead of a windows service, so
the application is run every 30min through a scheduled task. When the
email is received the received time is ok, but the sent time is
incorrect. In some emails the sent date/time is the same displaying
that the email was sent yesterday, but the latest one showed it was off
by 9 and a half hours. The date and time on the computer this is
running from is correct as is the exchange server and the computer it's
running on. The network admin said the time is handled by the domain
controller so if the time is off emails would not be sent at all.
Anyone have any ideas as to why this is occuring or how to fix it? Is
there something I need to write in my code to get the sent date/time to
appear correctly? Below is my code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Net.Mail;

namespace Harland_Email_Report
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{

}

private void Form1_Load(object sender, EventArgs e)
{
SqlConnection Conn = new SqlConnection();
{
Conn = new SqlConnection("server=***;user
id=***;password=***;database=***");
Conn.Open();
}

string emailbody = string.Empty;
emailbody = "<table width=599px><tr
align=center><th>Department</th><th># Molds</th><th># Stamps</th><th>#
Rejected</th><th> # Total</th></tr>";

SqlCommand DBCmd = new
SqlCommand("sp_Mold_Header_SEL_ByDepartmentDueDate", Conn);
DBCmd.CommandType = CommandType.StoredProcedure;

SqlDataReader myDataReader;
myDataReader = DBCmd.ExecuteReader();

while (myDataReader.Read())
{
emailbody = emailbody + "<tr align=center><td>" +
myDataReader["Department"].ToString() + "</td><td>" +
myDataReader["Number of Molds"].ToString() + "</td><td>" +
myDataReader["Number of Stamps"].ToString() + "</td><td>" +
myDataReader["Stamps Rejected"].ToString() + "</td><td>" +
myDataReader["Total Number of Stamps"].ToString() + "</td></tr>";
}

emailbody = emailbody + "</table>";
MailMessage mm = new MailMessage();
mm.To.Add("(e-mail address removed)");
mm.From = new MailAddress("(e-mail address removed)");
mm.Subject = "subject";
mm.BodyEncoding = Encoding.ASCII;
mm.IsBodyHtml = true;
mm.Body = emailbody;
SmtpClient client = new SmtpClient("***");
client.Send(mm);

Conn.Close();

this.Close();

}
}
}

thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top