C# sendmail task
I am trying to use a task on a SSIS package to send out an email using C# as the sendmail task wouldn't work (not set up to port 25 but 587).
this is the code that I have found (I know very little for C#) and I have tried:
#region Namespaces
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;
#endregion
namespace ST_73a495fd8aa540bcb5fc84ccdf3b837a
{
[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
public void Main()
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.office365.com");
mail.From = new MailAddress("xxx@xx.xx");
mail.To.Add("xxx@xx.xx");
mail.Subject = "Test Mail - 1";
mail.Body = "mail with attachment";
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("x:/...test.csv");
mail.Attachments.Add(attachment);
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("xxx@xx.xx", "testpassword");
SmtpServer.EnableSsl = true;
Dts.TaskResult = (int)ScriptResults.Success;
}
#region ScriptResults declaration
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
}
}
when trying to run this in the SSIS package after some time I get this error:
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()
Any ideas on what I can do to resolve this?
c# ssis
|
show 13 more comments
I am trying to use a task on a SSIS package to send out an email using C# as the sendmail task wouldn't work (not set up to port 25 but 587).
this is the code that I have found (I know very little for C#) and I have tried:
#region Namespaces
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;
#endregion
namespace ST_73a495fd8aa540bcb5fc84ccdf3b837a
{
[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
public void Main()
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.office365.com");
mail.From = new MailAddress("xxx@xx.xx");
mail.To.Add("xxx@xx.xx");
mail.Subject = "Test Mail - 1";
mail.Body = "mail with attachment";
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("x:/...test.csv");
mail.Attachments.Add(attachment);
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("xxx@xx.xx", "testpassword");
SmtpServer.EnableSsl = true;
Dts.TaskResult = (int)ScriptResults.Success;
}
#region ScriptResults declaration
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
}
}
when trying to run this in the SSIS package after some time I get this error:
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()
Any ideas on what I can do to resolve this?
c# ssis
2
this is not the full stack trace. please edit your post and provide full stack trace.
– Tazbir Bhuiyan
Nov 20 '18 at 10:46
1
@Tazbir Bhuiyan I have editted it and added the rest of it...
– fireshark519
Nov 20 '18 at 10:53
sorry to bother you again. the changes you made is not stack trace. stack trace is the error part you are getting( you provided some of it in the second code snippet). give the full stack trace
– Tazbir Bhuiyan
Nov 20 '18 at 10:58
not bothering at all @Tazbir Bhuiyan. When i try to execute the script task on the ssis package this is what I get on the execution results: DtsDebugHost.exe: DTS' has exited with code 0 (0x0). On the debugger itself it gives the following runtime error: Exception has been thrown by the target of an invocation. It then has the error I get at the bottom as part of the debugger but nothing else...I also get this on the ssis debugger Error: 0x1 at Script Task: Exception has been thrown by the target of an invocation. Task failed: Script Task
– fireshark519
Nov 20 '18 at 11:06
this might help: stackoverflow.com/questions/23681298/…
– Tazbir Bhuiyan
Nov 20 '18 at 11:16
|
show 13 more comments
I am trying to use a task on a SSIS package to send out an email using C# as the sendmail task wouldn't work (not set up to port 25 but 587).
this is the code that I have found (I know very little for C#) and I have tried:
#region Namespaces
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;
#endregion
namespace ST_73a495fd8aa540bcb5fc84ccdf3b837a
{
[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
public void Main()
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.office365.com");
mail.From = new MailAddress("xxx@xx.xx");
mail.To.Add("xxx@xx.xx");
mail.Subject = "Test Mail - 1";
mail.Body = "mail with attachment";
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("x:/...test.csv");
mail.Attachments.Add(attachment);
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("xxx@xx.xx", "testpassword");
SmtpServer.EnableSsl = true;
Dts.TaskResult = (int)ScriptResults.Success;
}
#region ScriptResults declaration
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
}
}
when trying to run this in the SSIS package after some time I get this error:
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()
Any ideas on what I can do to resolve this?
c# ssis
I am trying to use a task on a SSIS package to send out an email using C# as the sendmail task wouldn't work (not set up to port 25 but 587).
this is the code that I have found (I know very little for C#) and I have tried:
#region Namespaces
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;
#endregion
namespace ST_73a495fd8aa540bcb5fc84ccdf3b837a
{
[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
public void Main()
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.office365.com");
mail.From = new MailAddress("xxx@xx.xx");
mail.To.Add("xxx@xx.xx");
mail.Subject = "Test Mail - 1";
mail.Body = "mail with attachment";
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("x:/...test.csv");
mail.Attachments.Add(attachment);
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("xxx@xx.xx", "testpassword");
SmtpServer.EnableSsl = true;
Dts.TaskResult = (int)ScriptResults.Success;
}
#region ScriptResults declaration
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
}
}
when trying to run this in the SSIS package after some time I get this error:
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()
Any ideas on what I can do to resolve this?
c# ssis
c# ssis
edited Nov 20 '18 at 10:53
fireshark519
asked Nov 20 '18 at 10:38


fireshark519fireshark519
237
237
2
this is not the full stack trace. please edit your post and provide full stack trace.
– Tazbir Bhuiyan
Nov 20 '18 at 10:46
1
@Tazbir Bhuiyan I have editted it and added the rest of it...
– fireshark519
Nov 20 '18 at 10:53
sorry to bother you again. the changes you made is not stack trace. stack trace is the error part you are getting( you provided some of it in the second code snippet). give the full stack trace
– Tazbir Bhuiyan
Nov 20 '18 at 10:58
not bothering at all @Tazbir Bhuiyan. When i try to execute the script task on the ssis package this is what I get on the execution results: DtsDebugHost.exe: DTS' has exited with code 0 (0x0). On the debugger itself it gives the following runtime error: Exception has been thrown by the target of an invocation. It then has the error I get at the bottom as part of the debugger but nothing else...I also get this on the ssis debugger Error: 0x1 at Script Task: Exception has been thrown by the target of an invocation. Task failed: Script Task
– fireshark519
Nov 20 '18 at 11:06
this might help: stackoverflow.com/questions/23681298/…
– Tazbir Bhuiyan
Nov 20 '18 at 11:16
|
show 13 more comments
2
this is not the full stack trace. please edit your post and provide full stack trace.
– Tazbir Bhuiyan
Nov 20 '18 at 10:46
1
@Tazbir Bhuiyan I have editted it and added the rest of it...
– fireshark519
Nov 20 '18 at 10:53
sorry to bother you again. the changes you made is not stack trace. stack trace is the error part you are getting( you provided some of it in the second code snippet). give the full stack trace
– Tazbir Bhuiyan
Nov 20 '18 at 10:58
not bothering at all @Tazbir Bhuiyan. When i try to execute the script task on the ssis package this is what I get on the execution results: DtsDebugHost.exe: DTS' has exited with code 0 (0x0). On the debugger itself it gives the following runtime error: Exception has been thrown by the target of an invocation. It then has the error I get at the bottom as part of the debugger but nothing else...I also get this on the ssis debugger Error: 0x1 at Script Task: Exception has been thrown by the target of an invocation. Task failed: Script Task
– fireshark519
Nov 20 '18 at 11:06
this might help: stackoverflow.com/questions/23681298/…
– Tazbir Bhuiyan
Nov 20 '18 at 11:16
2
2
this is not the full stack trace. please edit your post and provide full stack trace.
– Tazbir Bhuiyan
Nov 20 '18 at 10:46
this is not the full stack trace. please edit your post and provide full stack trace.
– Tazbir Bhuiyan
Nov 20 '18 at 10:46
1
1
@Tazbir Bhuiyan I have editted it and added the rest of it...
– fireshark519
Nov 20 '18 at 10:53
@Tazbir Bhuiyan I have editted it and added the rest of it...
– fireshark519
Nov 20 '18 at 10:53
sorry to bother you again. the changes you made is not stack trace. stack trace is the error part you are getting( you provided some of it in the second code snippet). give the full stack trace
– Tazbir Bhuiyan
Nov 20 '18 at 10:58
sorry to bother you again. the changes you made is not stack trace. stack trace is the error part you are getting( you provided some of it in the second code snippet). give the full stack trace
– Tazbir Bhuiyan
Nov 20 '18 at 10:58
not bothering at all @Tazbir Bhuiyan. When i try to execute the script task on the ssis package this is what I get on the execution results: DtsDebugHost.exe: DTS' has exited with code 0 (0x0). On the debugger itself it gives the following runtime error: Exception has been thrown by the target of an invocation. It then has the error I get at the bottom as part of the debugger but nothing else...I also get this on the ssis debugger Error: 0x1 at Script Task: Exception has been thrown by the target of an invocation. Task failed: Script Task
– fireshark519
Nov 20 '18 at 11:06
not bothering at all @Tazbir Bhuiyan. When i try to execute the script task on the ssis package this is what I get on the execution results: DtsDebugHost.exe: DTS' has exited with code 0 (0x0). On the debugger itself it gives the following runtime error: Exception has been thrown by the target of an invocation. It then has the error I get at the bottom as part of the debugger but nothing else...I also get this on the ssis debugger Error: 0x1 at Script Task: Exception has been thrown by the target of an invocation. Task failed: Script Task
– fireshark519
Nov 20 '18 at 11:06
this might help: stackoverflow.com/questions/23681298/…
– Tazbir Bhuiyan
Nov 20 '18 at 11:16
this might help: stackoverflow.com/questions/23681298/…
– Tazbir Bhuiyan
Nov 20 '18 at 11:16
|
show 13 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391162%2fc-sharp-sendmail-task%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391162%2fc-sharp-sendmail-task%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
this is not the full stack trace. please edit your post and provide full stack trace.
– Tazbir Bhuiyan
Nov 20 '18 at 10:46
1
@Tazbir Bhuiyan I have editted it and added the rest of it...
– fireshark519
Nov 20 '18 at 10:53
sorry to bother you again. the changes you made is not stack trace. stack trace is the error part you are getting( you provided some of it in the second code snippet). give the full stack trace
– Tazbir Bhuiyan
Nov 20 '18 at 10:58
not bothering at all @Tazbir Bhuiyan. When i try to execute the script task on the ssis package this is what I get on the execution results: DtsDebugHost.exe: DTS' has exited with code 0 (0x0). On the debugger itself it gives the following runtime error: Exception has been thrown by the target of an invocation. It then has the error I get at the bottom as part of the debugger but nothing else...I also get this on the ssis debugger Error: 0x1 at Script Task: Exception has been thrown by the target of an invocation. Task failed: Script Task
– fireshark519
Nov 20 '18 at 11:06
this might help: stackoverflow.com/questions/23681298/…
– Tazbir Bhuiyan
Nov 20 '18 at 11:16