【问题标题】:Unable to send mail from SSIS using script task - time out无法使用脚本任务从 SSIS 发送邮件 - 超时
【发布时间】:2021-10-31 17:27:46
【问题描述】:

我使用循环创建了 SSIS 包。此包从 Reporting Services 导出 2 个文件(一个 pdf,一个 xlsx)。

通常,在通过 Outlook 发送导出文件的“脚本任务”中会出现超时错误。我看了但我想不通,我不是关于 c# 的出口。

错误描述。 ; System.Net.Mail.SmtpException:操作已超时。在 System.Net.Mail.SmtpClient.Send(MailMessage) .......

我的代码;

#region Help:  Introduction to the script task

#region Namespaces
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Text;
using System.Net;
using System.Net.Mail;
using System.IO;
using Microsoft.SqlServer.Dts;
#endregion

namespace ST_01aa093042ba46959a419d75a80d117c
{
    [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
    public partial class ScriptMain :
Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    {

        public void Main()
        {
            try
            {

                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("smtp.office365.com", 587);
                string fromString = (string)Dts.Variables["User::Email_From"].Value;
                string toString = (string)Dts.Variables["User::Email_TO"].Value;
                string ccString = (string)Dts.Variables["User::Email_CC"].Value;
                string attachmentName = (string)Dts.Variables["User::Pdf_Send_Path"].Value;
                string attachmentName1 = (string)Dts.Variables["User::Excel_Send_Path"].Value;
                string emailBody = (string)Dts.Variables["User::Email_Body"].Value;


                mail.From = new MailAddress(fromString);

                mail.To.Add(toString);
                mail.CC.Add(ccString);

                mail.Subject = (String)Dts.Variables["User::Email_Subject"].Value;
                mail.IsBodyHtml = false;

                System.Net.Mail.Attachment attachment;
                attachment = new System.Net.Mail.Attachment(attachmentName);
                mail.Attachments.Add(new Attachment(attachmentName));
                mail.Attachments.Add(new Attachment(attachmentName1));

                mail.Body = emailBody;

                SmtpServer.EnableSsl = true;

                SmtpServer.UseDefaultCredentials = false;
                SmtpServer.Credentials = new NetworkCredential("user@domain.com.tr", "1111");
                SmtpServer.Timeout = 100000;
                SmtpServer.Send(mail);
                Dts.TaskResult = (int)ScriptResults.Success;
            }
            catch (Exception ex)
            {
                ex.ToString();
                  MessageBox.Show(ex.ToString());
                Dts.Variables["User::Error_Value"].Value = 1;
                Dts.TaskResult = (int)ScriptResults.Failure;
            }


        }

        #region ScriptResults declaration
        enum ScriptResults
        {
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
        };
        #endregion

    }
}

【问题讨论】:

  • 你能从运行 SSIS 的服务器的 587 端口 ping smtp.office365.com 吗?可能是防火墙问题。
  • @MitchWheat,ping 成功(使用 telnet),防火墙也关闭了。
  • @AlwaysLearning,实际上它在正常的 etl 期间运行良好。但是,当 etl 进程比平时花费更长的时间时,它会出现超时错误。所以我必须重新启动服务器之后才能成功运行包。太奇怪了,我想我的小技巧可以解决这个错误。

标签: c# sql-server ssis


【解决方案1】:

这可能是因为您的文件的大小。如果它们超过 600 mb 我猜,你会得到错误。首先检查文件的大小。

【讨论】:

  • “导出和邮件发送”容器循环有 16 行。循环过程导出 1 个 excel 文件、1 个 pdf 文件并为每行发送 2 个文件。所有导出文件(16 个 excel,16 个 pdf)的总大小为 10mb。你检查过“邮件发送”C#代码吗?可能是,我错过了一些代码等。我想不通。
猜你喜欢
  • 2018-09-08
  • 1970-01-01
  • 1970-01-01
  • 2018-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-28
相关资源
最近更新 更多