Morning,I am sooo close. I have the query to get the email sent to the users but when I try to execute I get the message: MessageThe mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 1 (2010-12-01T09:39:44). Exception Message: Cannot send mails to mail server. (Syntax error in parameters or arguments. The server response was: 5.5.4 Invalid Address).)
Below is the code I'm using:declare @emailAddress varchar(255), @sql varchar(1000)declare Maillist cursorfor select distinct ''''+email_address+'''' FROM Psoft_sandbox1.dbo.vw_Get_Vendor_Info OPEN Maillist FETCH FROM Maillist into @emailAddressWHILE NOT (@@fetch_status=-1) BEGIN begin set nocount on select vendor,po,description,duedate,amtleft,@emailAddress from Psoft_sandbox1.dbo.vw_Get_Vendor_Info if @@ROWCOUNT >0 begin SET @SQL = 'select vendor,po,description,duedate,amtleft FROM Psoft_sandbox1.dbo.vw_Get_Vendor_Info where email_address= '+@emailAddress EXEC msdb.dbo.sp_send_dbmail @profile_name='AdminProfile', @recipients = @emailAddress, @query= @sql, @subject = 'Unprocessed Order', @attach_query_result_as_file = 0 ; end end FETCH NEXT FROM Maillist INTO @emailAddress END CLOSE Maillist DEALLOCATE Maillist
When I click execute these are the results I get:vendor po description duedate amtleft ---------- -------- ------------------------- -------- WEST 39888 Grey Anodize & Clean 09/23/10 29 'myemail@myemail.com'WEST 39922 Grey Anodize & Clean 09/23/10 1 'myemail@myemail.com'WEST 40028 B22232 INTERFACE PLATE 10/07/10 49 'myemail@myemail.com'WEST 40016 Alodine Surface Treatment 10/12/10 44 'myemail@myemail.com'WEST 40163 10060045 CLAMP,FOCUS CELL 10/26/10 48 'myemail@myemail.com'WEST 40137 Mask, Anodize 10/21/10 2 'myemail@myemail.com'WEST 40174 Alodine 10/21/10 31 'myemail@myemail.com'Mail queued.
Can anyone tell me what I need to do to make this work?Thanks in advance.Laura