如果发送邮件失败,请多次尝试执行发送邮件任务 [英] Implement Send Mail Task with multiple tries in case if its failed to send mail

查看:45
本文介绍了如果发送邮件失败,请多次尝试执行发送邮件任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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

我尝试了 SQL Server 代理作业步骤配置,用户可以选择配置重试次数和重试间隔,但它在失败时运行整个包,这不适合我的场景.我只需要单独运行发送邮件任务,以防多次尝试发送电子邮件失败.

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.

推荐答案

您提到的 C# 选项:

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<4) goto retry; //will try 4 times no matter what caused it to fall in to the catch
}

这篇关于如果发送邮件失败,请多次尝试执行发送邮件任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆