实现发送邮件任务,如果发送邮件失败,则进行多次尝试。

huangapple go评论84阅读模式
英文:

Implement Send Mail Task with multiple tries in case if its failed to send mail

问题

我已在我的包中实现了一个发送邮件任务,该任务在成功或失败时发送邮件通知。发送邮件任务有时会由于以下错误而失败。

任务失败:成功发送邮件任务
错误代码:-1073548540
错误消息:出现以下错误消息:“发送邮件失败。
System.IO.IOException:无法从传输连接读取数据:
现有连接已被远程主机强制关闭。
System.Net.Sockets.SocketException:现有连接已被远程主机强制关闭。”

我已向网络管理员报告了此问题,但他们建议如下。

从Mailhub接收到的错误有时在尝试建立连接时发生。
解决此问题的唯一方法是强制多次重试。如果可能的话,请尝试在您的应用程序中编码3-4次重试。

我确信可以通过脚本任务来实现这一点。我不确定在发送邮件任务失败的情况下是否可以实现多次重试。

我已经使用发送邮件任务实施了20多个包。我尝试以最小的更改来实施这种方法。

我尝试了使用SQL Server代理作业步骤配置,用户可以配置重试尝试和重试间隔,但它在失败时运行整个包,这不适用于我的情况。
如果发送电子邮件失败,我必须单独运行发送邮件任务,并进行多次重试。

英文:

I have implemented a Send Mail Task in my package which sends a mail notification on Success or Failure. The send mail task fails sometimes due to the below error.

Task failed: Send Mail Task with Success
Error Code: -1073548540
ErrorMessage: An error occurred with the following error message: "Failure sending mail. 
System.IO.IOException: Unable to read data from the transport connection: 
An existing connection was forcibly closed by the remote host.  
System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host"

I have reported the issue to network admin but they suggested the following.

The errors you are receiving from Mailhub can happen occasionally when trying to open a connection.  
The only way to resolve this issue is to force multiple retries.  If you can, please try to code in ~3-4 retries in your app.

I am sure that it can be done through a script task. I am not sure whether I can implement the multiple tries in case of failure using send mail task.

I have already implemented 20 plus packages with send mail task. I try to implement this approach with minimal change.

I tried the with SQL Server Agent job step configuration, the user has the option of configuring the Retry attempts and the Retry intervals but it runs the whole package on failure which is not suitable for my scenario.
I have to run only send mail task alone in case if it failed to send email with multiple tries.

答案1

得分: 1

Create a new package with a for container where you control the number of repetitions.
创建一个新的包,其中包含一个for容器,您可以控制重复次数。

Create a variable of type int.
创建一个int类型的变量。

Add a package execution task.
添加一个包执行任务。

In case of correct execution, assign a value to the variable that breaks the for loop.
在正确执行的情况下,将一个值赋给该变量,以终止for循环。

In case of error, you can register it in the database or whatever you want.
如果发生错误,您可以将其记录在数据库或任何您想要的地方。

The image below is for ssis-2008 but it is the same for ssis-2012.
下面的图片是针对ssis-2008的,但对于ssis-2012也是相同的。
实现发送邮件任务,如果发送邮件失败,则进行多次尝试。

英文:

To not modify your project much.

Create a new package with a for container where you control the number of repetitions.
Create a variable of type int.
Add a package execution task.
In case of correct execution, assign a value to the variable that breaks the for loop.
In case of error you can register it in database or whatever you want.

The image below is for ssis-2008 but it is the same for ssis-2012
实现发送邮件任务,如果发送邮件失败,则进行多次尝试。

答案2

得分: 1

以下是中文翻译的部分:

你提到了C#选项:

这是你正在寻找的逻辑:

int retryCount = 0;

retry:

try
{
     [构建并发送你的电子邮件]
}
catch
{
     retryCount++;
     if(retryCount < 4) goto retry; //无论导致进入catch块的原因是什么,都会尝试4次
}
英文:

You mentioned C# option:

here is the logic you are looking for:

int retryCount = 0;

retry:

try
{
     [Build and send your email]
}
catch
{
     retryCount++;
     if(retryCount&lt;4) goto retry; //will try 4 times no matter what caused it to fall in to the catch
}

huangapple
  • 本文由 发表于 2020年1月3日 17:34:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/59576097.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定