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.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 mails whereby sql 2005

Author  Topic 

pssheba
Yak Posting Veteran

95 Posts

Posted - 2008-02-18 : 08:59:56
Hi everyone
i get an error messgae running the following code

DECLARE @mailist VARCHAR(max)
SET @mailist=''
SELECT TOP 1 @mailist=@mailist + email +';'
FROM
email.dbo.mytable
SET @mailist=STUFF(@mailist,LEN(@mailist),1,'')
SET @mailist='''' + @mailist + ''''

EXEC msdb.dbo.sp_send_dbmail
@profile_name='my_mail_profile',
@recipients=@mailist,
@subject='mysubject',
@body_format='html',
@body=
'
<html>
<head>
<title>
problems with send_dbmail
</title>
</head>
<body>
this is not working
</body>
</html>
'

The error says:
quote:
Syntax error in parameters or arguments. The server response was: 5.5.4 Invalid Address)

At the other hand, if i assign a straightforward @recipints address such as

EXEC msdb.dbo.sp_send_dbmail
@profile_name='my_mail_profile',
@recipients=my@mail.com

It works
Anybody know why ?
Thanks

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-02-18 : 12:58:30
What does @mailist have? You can print out its value.
Go to Top of Page

pssheba
Yak Posting Veteran

95 Posts

Posted - 2008-02-18 : 14:30:10
quote:
Originally posted by rmiao

What does @mailist have? You can print out its value.


Hi rmiao,
The value of @mailist is: 'name@server.com'
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-02-18 : 20:32:39
Looks like you need dynamic sql.
Go to Top of Page
   

- Advertisement -