Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
pizzazzz
Yak Posting Veteran
55 Posts |
Posted - 2010-08-18 : 17:56:17
|
Hi I am trying to send attachments from my script task - when I run the following code without "Attachments.Add" it actually creates emails but when I try to add attachments it doesn't send any emails.this Script Task is within a ForEach loop so for each excel file it finds I want an email sent. anyone have an idea on how to get this sending w/attachments? the excel files are small - 5-15KB here's the code, i sanitized the email address and SMTP name, but you can get the idea:Dim myHtmlMessage As MailMessageDim mySmtpClient As SmtpClientmyHtmlMessage = New MailMessage("somebody@someplace.com", " somebody@someplace.com ", "Test Email from Script Task", "")myHtmlMessage.Attachments.Add(Dts.Variables("currentFile").ValuemySmtpClient = New SmtpClient("SMTP.server")mySmtpClient.Send(myHtmlMessageDts.TaskResult = ScriptResults.Success |
|
pizzazzz
Yak Posting Veteran
55 Posts |
Posted - 2010-08-18 : 18:11:05
|
here's the codes parsed correctly-Dim myHtmlMessage As MailMessageDim mySmtpClient As SmtpClientmyHtmlMessage = New MailMessage("somebody@someplace.com", " somebody@someplace.com ", "Test Email from Script Task", "")myHtmlMessage.Attachments.Add(Dts.Variables("currentFile").ValuemySmtpClient = New SmtpClient("SMTP.server")mySmtpClient.Send(myHtmlMessageDts.TaskResult = ScriptResults.Success |
|
|
pizzazzz
Yak Posting Veteran
55 Posts |
Posted - 2010-08-19 : 12:14:02
|
No one has ever had this problem before? No one ever sends emails with attachments throught script task??Ok, well, i thought I read something that the message has to be released or ended to send with attachment.if anyone can shed some loght on this I would appreciate it.thanks - pizzazzz |
|
|
pizzazzz
Yak Posting Veteran
55 Posts |
Posted - 2010-08-19 : 13:40:21
|
Ok, well, after 1 1/2 days of beating my head against the wall over this one, i finally figured it out and now send with attachments. Seems that the error was with the way I setup the attachment code to send my attachment. You have to DIM a variable as Attachment, then set that variable = new attachment(Dts.Variable("varName").Value) then attach - see my code snip for clarity. thanks for all who were trying to figure this one out with me... Dim strFile As Attachment strFile = New Attachment(Dts.Variables("currentFile").Value) myHtmlMessage.Attachments.Add(strFile) |
|
|
pizzazzz
Yak Posting Veteran
55 Posts |
Posted - 2010-08-23 : 13:19:44
|
thanks!beach-bum from san diego! |
|
|
|
|
|
|
|