我做了邮件服务。当我调试从数据库收到的数据时,它会将其发送给它,但是当我运行该服务时,它会发送一些数据。这是什么原因?
数据库中有10条记录。它是完全使用Debug发送的。当我运行 Windows服务或使用F5 终止调试时,某些部分正在发送(并非全部)。 我希望我能告诉你我的问题。
我认为问题在于我没有#34; Header"在我的邮件中。你的想法是什么?
与此同时,我为我糟糕的英语道歉。 谢谢你的一切。Please open the image
public bool SendMail(string Body, string Subject, List<string> ToList)
{
MailMessage mail = new MailMessage();
mail.From = From;
bool ReturnValue = false;
if (ToList.Count < 0)
{
return ReturnValue;
}
foreach (string Mailaddress in ToList)
{
mail.To.Add(Mailaddress);
}
mail.Subject = Subject;
mail.Body = Body ;
try
{
ServicePointManager.ServerCertificateValidationCallback =
delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; };
Client.Send(mail);
ReturnValue = true;
}
catch (Exception ex)
{
ILog log = LogManager.GetLogger(typeof(MailHelper));
log.Error(ex.Message, ex);
}
return ReturnValue;
}
protected MailHelper()
{
Client = new SmtpClient(ConfigurationManager.AppSettings["SmtpClient"].ToString());
From = new MailAddress(ConfigurationManager.AppSettings["MailAddressFrom"].ToString(), ConfigurationManager.AppSettings["MailAddressFromDisplayName"].ToString());
//ToList = new List<string>{"trying@trying.com.tr"};
Client.Port = Convert.ToInt32(ConfigurationManager.AppSettings["PortNumber"]);
Client.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["UserName"], ConfigurationManager.AppSettings["Password"]);
Client.EnableSsl = true;
}
<add key="log4net.Config" value="App.config" />
<add key="log4net.Config.Watch" value="True" />
<add key="ClientSettingsProvider.ServiceUri" value="" />
<add key="TimerInterval" value="3000" />
<add key="constr" value="Data Source=.;Initial Catalog=MailSending;Integrated Security=False;Persist Security Info=True;Integrated Security=SSPI"/>
DateTime davaTarih = Convert.ToDateTime(row["ModuleDate"]);
DateTime sonrakiDurusmaTarihi = Convert.ToDateTime(row["FollowingTrialDate"]);
string avukatName = row["Username"].ToString();
string esasNo = row["No"].ToString();
int countDays = Convert.ToInt32(row["countDays"]);
string kisaAciklama = row["ShortDescription"].ToString();
string sonrakidurusmaTar = "";
if (!DBNull.Value.Equals(row["FollowingTrialDate"]) && !DBNull.Value.Equals(row["countDays"]))
{
sonrakiDurusmaTarihi = Convert.ToDateTime(row["FollowingTrialDate"]);
}
else
{
sonrakiDurusmaTarihi = Convert.ToDateTime("");
sonrakidurusmaTar = "Sonraki Duruşma Bulunmamaktadır.";
// var sonrakiDurusma = DateTime.TryParse(SonrakidurusmaTar, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out sonrakiDurusmaTarihi); // FollowingTrialDate, null olarak gelirse hata vermesin amacıyla yazıldı.
}
ModuleSubject = " Mnemonic Hatırlatma Servisi";
ModuleBody = "Sayın ilgili, ;\r\n \r\n" +
"Modül: " + ModuleName + ";\r\n" +
"Esas no: " + esasNo + ";\r\n" +
"Dava tarihi: " + davaTarih.ToShortDateString() + ";\r\n" +
"Sonraki duruşma tarihi: " + sonrakiDurusmaTarihi.ToShortDateString() + ";\r\n" +
"Kalan Gün Sayısı: " + countDays + ";\r\n" +
"Kısa açıklama: " + kisaAciklama + ";\r\n\r\n" +
"Bilginize,";
MailHelper.Instance.SendMail(ModuleBody, ModuleSubject, ToList);
答案 0 :(得分:0)
我找到了答案。它被发送不完整,因为它快速发送邮件。解决方案是这样的:我在发送邮件之前和之后每秒等待六次,然后没有问题。
System.Threading.Thread.Sleep(6000);
Client.Send(mail);
System.Threading.Thread.Sleep(6000);