Sending An HTML Mail Message With The Script Task DOESNT WORK 4 ME
Oct 3, 2006
I set up the "Send Email Task" succesfully with "SMTP Connection to myExchangeSERVER" using "Windows Authentication"
However, as we all know - you can't have html format for the Send Mail Task. BUT this piece of code straight from MSDN doesnt work for me - each time it pops up this "Mail Sent Succesfully" - but I receive NO freaking EMAILs!!! Am I missing something or is it another one of those Microsoft "gotchas" ?
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.Net.Mail
Public Class ScriptMain
Public Sub Main()
Dim htmlMessageTo As String = "me.here@mydomain.com"
Dim htmlMessageFrom As String = "SSIS@mydomain.com"
Dim htmlMessageSubject As String = "SSIS Success - My Package"
Dim htmlMessageBody As String = _
Dts.Variables("User::HTMLtemplateText").Value.ToString
Dim smtpServer As String = "myExchangeSERVER"
SendMailMessage( _
htmlMessageTo, htmlMessageFrom, _
htmlMessageSubject, htmlMessageBody, _
True, smtpServer)
Dts.TaskResult = Dts.Results.Success
End Sub
Private Sub SendMailMessage( _
ByVal SendTo As String, ByVal From As String, _
ByVal Subject As String, ByVal Body As String, _
ByVal IsBodyHtml As Boolean, ByVal Server As String)
Dim htmlMessage As MailMessage
Dim mySmtpClient As SmtpClient
mySmtpClient = New SmtpClient(Server)
Dim myCred As New System.Net.CredentialCache()
mySmtpClient.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials
mySmtpClient.Send(htmlMessage)
MsgBox("Mail sent")
End Sub
while i was trying to execute the code for Sending an "HTML Mail Message with the Script Task" given at the link below http://msdn2.microsoft.com/en-us/library/ms403365.aspx
following error was encountered.
DTS Script Task has encountered an exception in user code: Project namecriptTask_098956444e9f4ae195c3565569c9444b The element cannot be found in a collection. This error happens when you try to retrieve an element from a collection on a container during execution of the package and the element is not there
at Microsoft.SqlServer.Dts.Runtime.Variables.get_Item(Object index) at ScriptTask_098956444e9f4ae195c3565569c9444b.ScriptMain.Main() in dts://Scripts/ScriptTask_098956444e9f4ae195c3565569c9444b/ScriptMain:line 29
i have developed a pakage which populates a two different tables with reference to the xml files added to a folder which is watched by a security WMI task.it is governed by a sequence container which contains three for each loop container for working on the different files.i have different event handlers set up inside for each loop container tasks which contains , data flow task, execute sql task, and moving the processed file to the desired destination.i want to set up a send mail task on the package level using event handler on error, where i have set up a task for looging the error to the error table , i have tried to collect all the error messages in a array list variable . and trying to use that variable a s a message source. i could not under stand if i set the propogation variable in the sequence container as false than will the onpost execute event will fire the onpostexecute event handler in the package level.if show how can i send only one email for all the errors of package with error looging.
Dear all, I have switched off the firewall settings on my system and as suggested im entering the minimal information and data to send the mail. but still the Mail Task is failing.. plz suggest.
Hopefully someone out there will have an idea as this is driving me nuts.
I've setup a task to email on success/failure and keep receiving the following message when executed:
Progress: The SendMail task is initiated. - 0 percent complete [Send Mail Task] Error: An error occurred with the following error message: "Failure sending mail.". Progress: The SendMail task is completed. - 100 percent complete Task Send Mail Task failed
When I configure Outlook Express on the same machine with the same settings it works.
On the SMTP Connection Manager I have left the default name, tested with both an IP address and Server Name, and no authentication or SSL.
On the Send Mail Task, it uses the above connection. The To: , From: , Subject fields are populated. Message SourceType is DirectInput, MessageSource is Test, Priority is Normal and no attachments or expressions etc.
Nothing useful is logged in the Event Viewer even with full logging turned on.
I keep getting a generic "Error Sending Mail" error. For testing purposes I am just trying to send using my own email account. What goes in the SMTP Server box in the connection manager? I have tried:
A - the exchange server address (SOMETHING.us.company.com) B - The SMTP properties I see when I look at the properties of my email address: (my.name@abcd.efgh.company.com) C - Just the end portion of the SMTP properties: (abcd.efgh.company.com) D - My email address (my.name@company.com)
I don't know what to enter, or what is giving me such a generic error message.
I know you can specify additional recipients in the To column by sepperating them with a semicolon. But whats the easiest way to send to several users, when the email address must be retrieved from a table with a query like this:
select email from problem_subscribers
where project = 'project1'
and statusmail = 'OnError'
So when the eventhandler gets an OnError i want the mail task to be sent to each problemsubscriber.
Lokendra writes "I have configured the Database mail profile and account in Sql Server 2005 but the mail is not sending and showing the following error message:
Error,235,The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 1 (2007-03-05T15:16:07). Exception Message: Cannot send mails to mail server. (Mailbox name not allowed. The server response was: Sorry<c/> that domain isn't in my list of allowed rcpthosts.). ),3000,90,,3/5/2007 3:16:07 PM,sa
but while in the same mail set up in previous instance of sql server 2005 the message was sending very well. After installing new instance of sql server 2005 the problem is arising.
Anybody can tell me that what I can do so that i can send mail using the SMTP databasemail account."
I want to send a simple mail using DATABASE MAIL feature in SQL SERVER 2005.
I've defined a public profile. I've enabled Database Mail stored procedures through the Surface Area Configuration .
but I can't send a mail with sp_send_dbmail stored procedure in 'msdb' database .
when I execute sp_send_dbmail in the Managment Studio the message is "Mail queued" but the mail is not sent.
Could it be related to Service Broker?Because the Surface Area Configuration indicates:'this inctance does not have a Service Broker endpoint'.If so, how should I make an endpoint?
here is the log file after executing sp_send_dbmail:
1) "DatabaseMail process is started"
2) "The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 2 (2007-03-08T00:49:29). Exception Message: Could not connect to mail server. (No connection could be made because the target machine actively refused it)."
The DatabaseMail90.exe is triggred ,so the mail is transfered to the mail queue but DatabaseMail90.exe couldn't give the mail to SMTP server.The promlem is what should I do to make DatabaseMail90.exe able to connect to the server?
I sent a HTML file as text message using xp_smtp_sendmail from my SQL server but the test email that I received doesn't look like the HTML file I have originally. Below are my codes:-
i am new at T-SQL and am trying to delete entries in a column that are not integers. i have the following code. why does it not work.
T-SQL
select invoicenumber from [control register] where convert(int, invoicenumber) like '%' if @@error > 0 begin delete from [control register] where invoicenumber = invoicenumber end go
gives me the error in Query analyser:
Server: Msg 245, Level 16, State 1, Line 1 Syntax error converting the nvarchar value '10-3-05' to a column of data type int.
@@error is supposed to pick up the error. why is it not.
please could you reply urgently at chris@captivedesign.co.za
We have a DTS package that sends smtp email from an ActiveX script task. The body of the emails are in template files that we read in and then replace values relating to the customer.
I am looking for suggestions of handling this process from an SSIS package. This is what our existing code does.
'Name or IP of Remote SMTP Server objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = DTSGlobalVariables("RemoteSMTPServer").Value objMessage2.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = DTSGlobalVariables("RemoteSMTPServer").Value
'Your UserID on the SMTP server objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "CustomerService" objMessage2.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "CustomerService"
'Your password on the SMTP server objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "cslogin" objMessage2.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "cspassword"
If oRS.Fields("Rejected").value = 1 Then 'Rejection Message objMessage.Subject = "electronic request notification"
If oRS.Fields("ProductType").value = "Fixed" Then Set htmlTextStream = fso.OpenTextFile (DTSGlobalVariables("EmailTemplateRejectedFixed").Value) Else Set htmlTextStream = fso.OpenTextFile (DTSGlobalVariables("EmailTemplateRejectedVariable").Value) End If
Else 'Successful results objMessage.Subject = "electronic confirmation #" + CSTR(oRS.Fields("ConfirmationId").value) objMessage2.Subject = "Customer request for hard copy of contract"
If fso.FileExists(termDocument) Then objMessage.AddAttachment termDocument objMessage2.AddAttachment termDocument End If
If oRS.Fields("ProductType").value = "Fixed" Then Set htmlTextStream = fso.OpenTextFile (DTSGlobalVariables("EmailTemplateSuccessFixed").Value) Else Set htmlTextStream = fso.OpenTextFile (DTSGlobalVariables("EmailTemplateSuccessVariable").Value) End If
If oRS.Fields("SendHardCopy").value = True AND oRS.Fields("Rejected").value = 0 Then
' Attach Instructions for Hard Copy delivery instructionDocument = DTSGlobalVariables("TermDocumentsRepository").Value + "Instructions.txt"
set file = fso.CreateTextFile(instructionDocument, true) file.WriteLine("The customer has requested a hard copy of their contract to be sent to them.") file.WriteLine("") file.WriteLine("Instructions:") file.WriteLine("1) Print the email") file.WriteLine("2) Print the attached Terms & Conditions document") file.WriteLine("3) Mail both items to the address below") file.WriteLine("") file.WriteLine("Customer Address:") file.WriteLine(oRS.Fields("ContactFirstName").value + " " + oRS.Fields("ContactLastName").value) file.WriteLine(oRS.Fields("BillingAddress1").value) If oRS.Fields("BillingAddress2").value <> "" Then file.WriteLine(oRS.Fields("BillingAddress2").value) End If file.WriteLine(oRS.Fields("BillingCity").value + ", " + oRS.Fields("BillingState").value + " " +oRS.Fields("BillingZip").value) file.Close set file=nothing
objMessage2.AddAttachment instructionDocument
fso.DeleteFile(instructionDocument)
objMessage2.Send End If
set objMessage = nothing set objMessage2 = nothing
can someone tell me why this sql statement doesnt work?
SQL = "SELECT (Count(department_id) as 'totals' FROM nonconformance WHERE department_id = '7'),(Count(department_id) as 'totals2' FROM nonconformance WHERE department_id = '1') FROM nonconformance"
Can someone tell me why this thing in the end return Null?
declare @uz_id uniqueidentifier set @uz_id=null set @uz_id= case @Uz_ID when null then '00000000-0000-0000-0000-000000000000' else @Uz_ID end select @uz_id
...it should return '00000000-0000-0000-0000-000000000000' in my opintion
P.S. When I say return i mean the value that is shown after 'select @uz_id' is executed:)
This is an insert statement i'm trying to run. I want it to only insert this recird if the corresponding EMPLOY_REF exists in the EMPLOYEE table. Heres my statement:
INSERT INTO SALHISTY(EMPLOY_REF, SALARY, SAL_REASON, SAL_DATE) VALUES ('8971','175000.0000','ANNRV','2007-04-01 00:00:00.000') WHERE '8971' IN (SELECT EMPLOY_REF FROM EMPLOYEE)
This is the error message i'm getting.
Server: Msg 156, Level 15, State 1, Line 3 Incorrect syntax near the keyword 'WHERE'.
from ( select count(*) as Patients, [pct of res] as pct from testing where [18 week wait] <= 18 group by [pct of res] ) as a right outer join (select distinct[pct of res] from testing) as c on a.pct=c.[pct of res]and a.pct <> 'null' --is not null
(select count(*) as Patients, [pct of res] as pct from testing where [18 week wait] >18 group by [pct of res] ) as a left outer join as b on c.[pct of res]=b.pct
Hi. I have problems with sending a mail from SQL Server: SQL Mail starts. Command: xp_sendmail 'MRudyk','Halo!' returns:Unknown recipient: Parameter '@recipients', recipient 'Mrudyk' 'Mrudyk' is valid recipient...
I have the following in my commandtext but it doesnt seem to replace the LanguageColumnName variable: Dim cmd As New SqlCommand("SELECT '+@LanguageColumnName+' FROM tblSports a INNER JOIN tblUsersAndSports b ON a.SportID=b.SportID " & _ "WHERE b.UserCode=@UserCode", MyConnection) cmd.Parameters.Add(New SqlParameter("@UserCode", UserCode)) cmd.Parameters.Add(New SqlParameter("@LanguageColumnName", LanguageColumnName))I have tried '+@LanguageColumnName+' and also just @LanguageColumnName but this variable isnt replaced for some reason.The value of LanguageColumnName is "de"...the funny thing is that when I just type my command like the following it DOES work..:SELECT de FROM tblSports a INNER JOIN tblUsersAndSports b ON a.SportID=b.SportID " & _ "WHERE b.UserCode=@UserCodeWhat am I doing wrong?
I have my db in a pocket pc wm5.0, I just want to make a simple query select * from table where pk = '1' but this doesnt work, if you tried any other field else than the primary key it works... WHY???
would it be a problem with the sdf file? help please!!!
I have an issue. When I am performing a Merge Join using two fields of type DT_WSTR on both sides of the Join, the Dataviewer after the Join only shows the left side 2 key fields having values populated but both fields from the right hand side as being NULL. The Dataviewers I put in before the join show both sides of the join fields being populated ( 2 sides x 2 fields ). If I remove one of the fields from the join it shows both fields from the left side and the right side of the join being populated . I am trying to knock out duplicate values from the insert using 'genuine' Nulls from the right hand side so I need both parts of the 'Key'. I have checked the adnvanced tab that ignores Case etc but has had no effect.
I am using the technique from here : http://www.sqlis.com/311.aspx
Is this an SSIS bug ??? It is driving me up the wall.
HI All,I have started sqlserver in single user mode and changed filename in sysaltfiles for tempdb too point to new location. While starting sqlserver in normal it points to the old path and doesnt get updated with the new path.1.)is there any systable still to be altered???2.) i have even tried alter database, doesnt work.3.)The master files have been taken from server1 (where tempdb points to d:data) to server2 ( where i need to point tempdb to point E:mssqldata). i can detach and attach msdb and model successfully, but in the case of tempdb, i cant either alter sysaltfiles or detach and attach tempdb to new path., too tired in trying all the possiblities... Is there any possibility to update tempdb to point to new path???
i've made a report containing a subreport. the subreport is in a table. the table headers should repeat. but if the subreport expands more than one site, the table header doesnt repeat.
okay. i could place the table header in report header, but in report header i cant use fields from a dateset.
hi, i hope this is the correct forum?i have developed a small asp.net 2.0 web site with vwd using sqlExpress which appears to just bean data file and a log file in my app_data directory. there are two databases, the users one that is created by the login manager and my own that i created to store data. this all works fine on my laptop. i have an xp-pro machine setup with IIS and the frontpage web extentions, i have also installed the .net framework v2.0 on it and done all the windows updates. i have given app_data read/write access for the aspnet and network service users.i used the copy site feature of vwd to install on the xp box and although the site seems to workwhen it needs to bind a gridview to my sqldatasource it gives an error Cannot open user default database. login failed.Loginfailed for user 'rlxpaspnet'Any ideas? i have googled and tried all sorts, but to no avail, so i throw my self on your mercy!Cheers,russ
I've a problem with my database. Till yesterday the option for Auto Grow of Database (10 %) was working very fine, but now it seems to be some problems with it. Finally I had to specify a restricted size for the database and then it again startd to give me some space in the database to write in. Ideally it should have worked automatically, isnt it ???
There is no problem with the space on the drive, I still have some 76 gb of free space there ...
Hello, I tried this and it doesnt work, I just started up the service with -T flag on default instance but I havent been able to start it with -T flag 1400 on named instances.
How can I Know that the directory MSSQL.4 is the MIRROR instance??
C:Archivos de programaMicrosoft SQL ServerMSSQL.4MSSQLBinn>sqlservr.exe -T 1400 MIRROR
I tried LUCHOMIRROR, MSSQLSERVER$MIRROR
and It doesnt work
Thanks
Another question I have, in the documentation it says that mirroring is only for evaluation purposes and not for production environments, what does it suppose to mean? MSFT didnt test the mirroring feature enough? If its not suppoerted why its included..?
Microsoft support policies do not apply to the database mirroring feature in SQL Server 2005. Database mirroring is currently disabled by default, but may be enabled for evaluation purposes only by using trace flag 1400 as a startup parameter. (For more information about trace flags, see Trace Flags (Transact-SQL).) Database mirroring should not be used in production environments, and Microsoft support services will not support databases or applications that use database mirroring. Database mirroring documentation is included in SQL Server 2005 for evaluation purposes only, and the Documentation Policy for SQL Server 2005 Support and Upgrade does not apply to the database mirroring documentation.
I need info from 2 Tables. from the Table 2 I just need 1 column. When i ask for this column the output I get is data repeating themselve many times.
Distinct, should give me unique data, but is doesnt.... the code:
SELECT DISTINCT FSenddate, FSupplyIDName, FSupplyerNumber,FBillNo,FSourceBillNo,FItemName,FItemModel, FAuxQty,FAuxTaxPrice,FHeadSelfP0237 FROM vwICBill_26 WHERE FSenddate BETWEEN DATEADD(dd,-14,GETDATE()) AND GETDATE()
This code just works in Table1 (vwICBill_26)
but with table 2 (vwICBill_1)
SELECT DISTINCT vwICBill_26.FSenddate,vwICBill_26.FSupplyIDName, vwICBill_26.FSupplyerNumber,vwICBill_26.FBillNo, vwICBill_26.FSourceBillNo,vwICBill_26.FItemName, vwICBill_26.FItemModel,vwICBill_26.FAuxQty, vwICBill_26.FAuxTaxPrice,vwICBill_26.FHeadSelfP0237, vwICBill_1.FDate,vwICBill_1.FContractBillNo FROM vwICBill_26,vwICBill_1 WHERE vwICBill_26.FSenddate BETWEEN DATEADD(dd,-14,GETDATE()) AND GETDATE() AND vwICBill_1.FContractBillNo=vwICBill_26.FSourceBillNo
The last sentence is the problem I want that it shows me the data that is not equal. As soon as I implement the not equal it shows me the massive repeating data. I mean even without the last sentence I get this data output.
All together, I want a clear database output without data repeating. Any ideas how it may work without DISTINCT?
I think this problem is a typical amateure problem, but I would apreciate help!
Msg 1008, Level 16, State 1, Procedure P_SEL_ALLPERSONAS, Line 13
The SELECT item identified by the ORDER BY number 1 contains a variable as part of the expression identifying a column position. Variables are only allowed when ordering by an expression referencing a column name.