无法使用脚本任务从 SSIS 发送邮件 [英] Unable to send mail from SSIS using script task
本文介绍了无法使用脚本任务从 SSIS 发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 SSIS 中创建了脚本任务并编写了 C# 程序来发送邮件.是这样的.
I have created script task in SSIS and wrote C# program to send mail. it is like this.
public void Main()
{
MailMessage mail = new MailMessage("from@email.com", "to@gmail.com", "subject", "body");
SmtpClient client = new SmtpClient("smtp.office365.com", 587);
client.Credentials = new NetworkCredential("from@email.com", "password!!!");
client.EnableSsl = true;
client.Send(mail);
Dts.TaskResult = (int)ScriptResults.Success;
}
当我尝试运行该程序时,它显示以下异常.
When i tried to run the program, it shows the following exception.
Exception has been thrown by the target of an invocation.
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
当我在 C# 控制台模式下运行此代码时,它工作正常.
When i run this code in C# console mode it's working fine.
我尝试在 SSIS 中发送邮件任务,但它不起作用.所以我使用了脚本任务.
I tried send mail task in SSIS, but it is not working. So i used script task.
关于如何解决这个问题的任何想法?
any ideas on how to solve this?
推荐答案
我终于找到了解决方案.
I finally found the solution.
我像这样修改了代码..
i modified the code like this..
public void Main()
{
MailMessage mail = new MailMessage("from@email.com", "to@gmail.com", "subject", "body");
SmtpClient client = new SmtpClient("smtp.office365.com", 587);
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("from@email.com", "password!!!");
client.Send(mail);
Dts.TaskResult = (int)ScriptResults.Success;
}
然后它起作用了.:)
这篇关于无法使用脚本任务从 SSIS 发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文