我有一個奇怪的問題,但不知道該用它來做什麼,有時 - 套接字錯誤10054從電子郵件服務器,SMTP客戶端
我有準備一些數據的.NET控制檯應用程序和FTP的過來 後操作完成它應該發出一封確認電子郵件 - 只有發生的情況是,有時電子郵件被接收,有時不會
應用程序在SQL工作代理程序中使用sql server 2014運行在該工作臺上2014 該應用程序在同一臺服務器上作爲數據庫,所有者是sa並且作業在SQL Server代理下運行 - SQLSERVERAGENT對文件夾具有所有權利
使用郵件服務器的MDaemon,對服務器日誌檢查它表明:
Fri 2016-08-12 06:28:50.387: 01: ----------
Fri 2016-08-12 06:31:24.154: 05: Session 834167; child 0001
Fri 2016-08-12 06:31:24.154: 05: Accepting SMTP connection from xxx to xxx
Fri 2016-08-12 06:31:24.164: 03: --> xxx ESMTP MDaemon 16.0.4; Fri, 12 Aug 2016 06:31:24 +1000
Fri 2016-08-12 06:31:24.164: 03: --> 220-Unauthorized relay prohibited.
Fri 2016-08-12 06:31:24.164: 03: --> 220 All transactions and IP are logged.
Fri 2016-08-12 06:31:24.167: 02: <-- EHLO OCSQL2
Fri 2016-08-12 06:31:24.168: 03: --> xxx Hello OCSQL2 [10.10.45.34], pleased to meet you
Fri 2016-08-12 06:31:24.168: 03: --> 250-ETRN
Fri 2016-08-12 06:31:24.168: 03: --> 250-AUTH LOGIN CRAM-MD5 PLAIN
Fri 2016-08-12 06:31:24.168: 03: --> 250-8BITMIME
Fri 2016-08-12 06:31:24.168: 03: --> 250-ENHANCEDSTATUSCODES
Fri 2016-08-12 06:31:24.168: 03: --> 250-STARTTLS
Fri 2016-08-12 06:31:24.168: 03: --> 250 SIZE
Fri 2016-08-12 06:31:24.168: 02: <-- MAIL FROM:<xxx>
Fri 2016-08-12 06:31:24.170: 01: xxx is an alias for xxx
Fri 2016-08-12 06:31:24.170: 03: --> 250 2.1.0 Sender OK
Fri 2016-08-12 06:31:24.170: 02: <-- RCPT TO:<xxx>
Fri 2016-08-12 06:31:24.175: 03: --> 250 2.1.5 Recipient OK
Fri 2016-08-12 06:31:24.175: 02: <-- RCPT TO:<xxx>
Fri 2016-08-12 06:31:24.265: 03: --> 250 2.1.5 Recipient OK
Fri 2016-08-12 06:31:24.266: 02: <-- RCPT TO:<xxx>
Fri 2016-08-12 06:31:24.270: 03: --> 250 2.1.5 Recipient OK
Fri 2016-08-12 06:31:24.270: 02: <-- RCPT TO:<xxx>
Fri 2016-08-12 06:31:24.275: 03: --> 250 2.1.5 Recipient OK
Fri 2016-08-12 06:31:24.276: 02: <-- RCPT TO:<xxx>
Fri 2016-08-12 06:31:24.281: 03: --> 250 2.1.5 Recipient OK
Fri 2016-08-12 06:31:24.281: 02: <-- RCPT TO:<xxx>
Fri 2016-08-12 06:31:24.286: 03: --> 250 2.1.5 Recipient OK
Fri 2016-08-12 06:31:24.286: 02: <-- DATA
Fri 2016-08-12 06:31:24.290: 01: Creating temp file (SMTP): e:\mdaemon\queues\temp\md50000008212.tmp
Fri 2016-08-12 06:31:24.290: 03: --> 354 Enter mail, end with <CRLF>.<CRLF>
Fri 2016-08-12 06:31:24.295: 01: Message size: 552 bytes
Fri 2016-08-12 06:31:24.323: 04: Socket error sending response to DATA
Fri 2016-08-12 06:31:24.324: 04: * Socket error 10054 - Connection was reset by the other side!
Fri 2016-08-12 06:31:24.324: 04: SMTP session terminated (Bytes in/out: 841/540)
代碼中的應用:
public bool sendUploadNotification() {
var arrToEmail = toEmail.Split(';');
var arrCCEmail = ccEmail.Split(';');
MailMessage msg = new MailMessage();
string body;
string subject;
bool result = false;
if (logger.IsDebugEnabled) { logger.Debug("sending upload email"); }
try {
body = ReadBody();
subject = GetSubject();
if (logger.IsDebugEnabled) {
logger.Debug("ToEmail:" + toEmail + "," + "CCEmail:" + ccEmail + ",Subject:" + subject);
}
msg.IsBodyHtml = true;
msg.BodyEncoding = Encoding.UTF8;
msg.SubjectEncoding = Encoding.UTF8;
msg.From = new MailAddress(fromEmail,fromName);
msg.Subject = subject;
msg.Body = body;
foreach (var item in arrToEmail) {
msg.To.Add(new MailAddress(item));
}
foreach (var item in arrCCEmail) {
msg.CC.Add(new MailAddress(item));
}
client.Send(msg);
result = true;
if (logger.IsInfoEnabled) {
logger.Info("Upload confirmation email sent");
}
}
catch (Exception ex) {
if (logger.IsErrorEnabled) {
logger.Error("Error sending upload confirmation email", ex);
}
sendExceptionMail(ex);
result = false;
}
return result;
}
我沒有得到任何異常的應用程序日誌,一切都成功完成。
服務器有一個發送電子郵件不受SQL代理觸發其他.NET模塊這似乎並不存在這個問題,但是其他模塊,它們被稱爲在運行時從網站
這個問題似乎隨機發生,大多數時候它不工作,有時我已經收到電子郵件按預期,沒有任何應用程序或服務器的變化
我不明白爲什麼它失敗,搜索谷歌出現有些問題與Windows 2008服務器有關的TCP/IP堆棧,但我在Windows服務器2012 R2 - 我可以想到的唯一的事情,如果它可能必須做的權限,但它有效
謝謝,我會嘗試它,當我可以安排更改 – Danish