SmtpClient - 无法循环发送电子邮件 [英] SmtpClient - unable to send email in a loop
问题描述
您好, 我使用的是System.Net.Mail.SmtpClient发送电子邮件。 在一个循环中,我正在调用一个以一分钟的时间间隔发送电子邮件的函数。 功能流程: - 创建SmtpClient即客户端。 设置client.ServicePoint.maxIdleTime = 0; client.ServicePoint.ConnectionLeaseTimeout = 0; groupName = client.ServicePoint.ConnectionName ; 表单MailMessage client.Send(MailMessage) 关闭客户端 - client.ServicePoint.CloseConnectionGroup (groupName) 并设置client = null; 发送第一封电子邮件正确。 当调用SmtpClient.Send发送第二封电子邮件时 - 它会抛出异常。 SmtpException-发送电子邮件失败。 StatusCode - GeneralFailure。 InnerException - 无法从tran读取数据运动连接:net_io_connectionclosed。 如果我将发送电子邮件的时间间隔从一分钟增加到两分钟,程序可以正常工作正确。 我的理解是我通过调用CloseConnectionGroup和 设置ConnectionLeaseTimeout = 0. 如果我使用netstat实用程序检查网络连接,则显示与SMTP服务器的连接处于CLOSE_WAIT状态且未被删除直到服务器的连接超时到期,即60秒。 此外,每次我创建新的连接以发送电子邮件时,为什么我不能只打开一个新连接并让旧的连接超时。 任何人都可以解释为什么我不能以一分钟的间隔发送电子邮件吗? FYI:这是一个控制台应用程序。
谢谢,
问候,
Aparna
您好Aparna,
您有没有找到解决方案?我有相同的问题循环通过电子邮件。前1个没问题,之后就失败了。感谢。搜索结果,搜索添
Hi , I am using System.Net.Mail.SmtpClient to send email. In a loop I am calling a function that sends email at one minute time interval. The flow of function:- Create SmtpClient i.e. client. Set client.ServicePoint.maxIdleTime = 0; client.ServicePoint.ConnectionLeaseTimeout = 0; groupName = client.ServicePoint.ConnectionName; Form MailMessage client.Send( MailMessage) Close client - client.ServicePoint.CloseConnectionGroup(groupName) and set client = null; The first email is send properly. When SmtpClient.Send is called for sending second email - it throws Exception. SmtpException- Failure sending email. StatusCode - GeneralFailure. InnerException - Unable to read data from transport connection:net_io_connectionclosed. If I increase the time interval at which I send email from one minute to two minute the program works properly. My understanding is I am forcing SMtpClient to close connection with server by calling CloseConnectionGroup and setting ConnectionLeaseTimeout = 0. If I use netstat utility to check network connection it shows the connection to SMTP Server goes in CLOSE_WAIT state and is not dropped until Server's connection timeout expires i.e 60 seconds. Moreover, everytime I am creating a new connection to send email, so why cannot I just open a new connection and let the old connection timeout. Can anyone explain why I am not able to send email at one minute interval? FYI: This is a console application. Thanks, Regards, Aparna
Hi Aparna,
Did you ever figure out a solution to this? I have the same issue looping through e-mails. First 1 goes fine, after that it fails. Thanks.
Tim
这篇关于SmtpClient - 无法循环发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!