SmtpClient を使用して電子メールを送信するアプリケーションがありますが、アプリケーションを閉じるまで電子メールは送信されません。問題の解決策を見つけるために検索して検索しましたが、見つけることができません。
システムには Symantec アンチウイルスがインストールされていますが、これが問題である可能性があります。
誰でもこの問題の解決策を持っていますか?
これが私が使用しているコードです。
public class EMail
{
private string server;
public string Server {get{return this.server;}set{this.server = value;}}
private string to;
public string To {get{return this.to;}set{this.to = value;}}
private string from;
public string From {get{return this.from;}set{this.from = value;}}
private string subject;
public string Subject {get{return this.subject;}set{this.subject = value;}}
private string body;
public string Body {get{return this.body;}set{this.body = value;}}
public EMail()
{}
public EMail(string _server, string _to, string _from, string _subject, string _body)
{
this.Server = _server;
this.To = _to;
this.From = _from;
this.Subject = _subject;
this.Body = _body;
}
public void Send()
{
using(System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(this.From, this.To, this.Subject, this.Body))
{
message.IsBodyHtml = true;
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(this.Server);
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
//I have tried this, but it still does not work.
//client.ServicePoint.ConnectionLeaseTimeout = 0;
try
{
client.Send(message);
}
catch(System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString());
}
}
}
}
編集:
電子メールは最終的に 2 ~ 3 分後に送信されることがわかりました。Exchange サーバーによってキューに入れられているように見えます。または、SmtpClient 接続が最終的にタイムアウトになり、サーバーによって閉じられたようです。
編集:
私が試してみました。
client.ServicePoint.ConnectionLeaseTimeout = 1;
client.ServicePoint.MaxIdleTime = 1;