SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to send email to multiple recipients
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

imranabdulaziz
Yak Posting Veteran

83 Posts

Posted - 06/03/2008 :  08:14:05  Show Profile  Reply with Quote
Dear all,
i am using sql server 2005.
i am facing a scenario where i have to send mail to single or multiple user depending on the query.
i tried this stmt to send mail to multiple receipints
EXEC msdb.dbo.sp_send_dbmail @profile_name = 'imran' , @recipients= 'imran.khan@bbraun.com;amol.puranik@bbraun.com', @subject = 'Test mail'

it succesfully sent mail.

Now i want to send mail depending on query. with single employee it is no issue. but if it is more then one employee how can i mail to multiple recipient.

That is my question is in this sp to send multiple recepients one has to separates addresses with ; semi colon how can i arreange recipient so that ; comes in between.

Thank you.



visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 06/03/2008 :  08:16:41  Show Profile  Reply with Quote
Is email addresses coming from some table field?
Go to Top of Page

imranabdulaziz
Yak Posting Veteran

83 Posts

Posted - 06/03/2008 :  08:30:13  Show Profile  Reply with Quote
Yes it is coming from employee_refernce where email id is stored against empcode

THANK YOU
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 06/03/2008 :  08:33:03  Show Profile  Reply with Quote
WHere will you get information reg whom to be mailed? Or do you want to mail to all employees in table?
Go to Top of Page

imranabdulaziz
Yak Posting Veteran

83 Posts

Posted - 06/03/2008 :  08:35:59  Show Profile  Reply with Quote
EVEN IF U TELL ME HOW TO SEND MAIL TO ALL THE EMPLOYEE MY PROBLEM WILL BE SOLVED
THANK YOU
Go to Top of Page

Ashish Gupta
Starting Member

India
1 Posts

Posted - 10/28/2009 :  03:56:08  Show Profile  Reply with Quote

Hi Imran ,
I have gone though the same senario which you are facing, what i did was created a table passed all the email adress in it , and then send the mail picking the email from table, using while loop.

use msdb
EXEC sp_send_dbmail @profile_name='My gmail live account',
@recipients=@email_address,
@subject='Test message',
@body='hope it helps'


Ashish Gupta

Go to Top of Page

srikanth448
Starting Member

India
1 Posts

Posted - 06/25/2013 :  05:41:07  Show Profile  Reply with Quote
Hello All,

I do have save requirement of sending multiple emails to users depending on the query.

Please can you guide me on this also provide me steps.

thanks in advance....
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 06/25/2013 :  05:59:32  Show Profile  Reply with Quote
something like


DECLARE @Receipientlist varchar(8000)
SET @ReceipientList = STUFF((SELECT ';' + emailaddress FROM Your query here FOR XML PATH('')),1,1,'')


EXEC sp_send_dbmail @profile_name= your email profile in db,
@recipients=@Receipientlist,
@subject='your subject here',
@body='body message here' 
...


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000