我放置了一个包含代码的脚本任务,以便将电子邮件On Error
发送到Event Handler
。现在我需要附上或发送带有消息的输出或错误日志。
我搜索过,无法找到明确的解决方案。
注意: MailAuthentication 是一个包含身份验证信息的类。
电子邮件代码:
[Microsoft.SqlServer.Dts.Tasks.ScriptTask.
SSISScriptTaskEntryPointAttribute]
public partial class ScriptMain : Microsoft.SqlServer.Dts.
Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
public static string EmailBody()
{
StringBuilder userMessage = new StringBuilder();
userMessage.Append("Mail Body Text");
userMessage.Append("Mail Body Text");
userMessage.Append("\n\nMail Body Text");
userMessage.Append("\nMail Body Text");
userMessage.Append("\nMail Body Text");
return userMessage.ToString();
}
public void Main()
{
var fromAddress = new MailAddress(MailAuthentication.mailFrom, "From Me");
var toAddress = new MailAddress(MailAuthentication.mailTo, "To Someone");
const string fromPassword = MailAuthentication.password;
const string subject = "Who Shot the couch";
string body = EmailBody().ToString();
var smtp = new SmtpClient
{
Host = MailAuthentication.liveSMTP,
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword),
Timeout = 20000
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
}
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
}