sending email from SQL

Hi, I have the following code which is working fine when running by itself

--IF @@ROWCOUNT > 0 
BEGIN


    EXEC msdb.dbo.sp_send_dbmail
	 @body_format='HTML',
      @profile_name = 'PDN',

	  @recipients = 'aaa@hotmail.com',
	  @blind_copy_recipients = "bbb@bbb.com",

      @subject = 'Deal Tracker notification',
      @body = 'test'

END

Open in new window


But when I put it in another sp, it does not work. There is no error, it is just that email does not get sent out.  any ideas?  thanks
mcrmgAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pawan KumarDatabase ExpertCommented:
how you are calling it ?
0
Pawan KumarDatabase ExpertCommented:
Please try like this ..

CREATE PROC spEmail
AS
BEGIN

	EXEC msdb.dbo.sp_send_dbmail
	@body_format='HTML',
	@profile_name = 'PDN',

	@recipients = 'aaa@hotmail.com',
	@blind_copy_recipients = 'bbb@bbb.com',
	@subject = 'Deal Tracker notification',
	@body = 'test'

END

Open in new window



>>EXECUTION
EXEC spEmail

Open in new window

0
Pawan KumarDatabase ExpertCommented:
Changed this line -

@blind_copy_recipients = "bbb@bbb.com"

to

@blind_copy_recipients = 'bbb@bbb.com'
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

mcrmgAuthor Commented:
this is my sp

USE [pdn]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[st_DailyEmail]
@user as varchar(50),
@email as varchar(50)
AS	
 
DECLARE @MAIL_BODY VARCHAR(8000)
DECLARE @MAIL_BODY1 VARCHAR(8000)
 
--/* HEADER */
SET @MAIL_BODY = 'HTML code here'
 
 SET @MAIL_BODY1 = ''
 SELECT         @MAIL_BODY1 = @MAIL_BODY1 + 
			'code here'
FROM            tables
where convert(varchar(10),[ActivityDate],101) = convert(varchar(10),getdate(),101) and
Assigned = @user


IF @@ROWCOUNT > 0 
BEGIN
SET @MAIL_BODY = @MAIL_BODY + @MAIL_BODY1 + '</table>'
 --USE [msdb]
    EXEC msdb.dbo.sp_send_dbmail
	 @body_format='HTML',
      @profile_name = 'PDN',
      @recipients = @email,
	  @blind_copy_recipients = 'bbb@bbb.com;ccc@ccc.com',
      @subject = 'notification',
      @body = @MAIL_BODY

END

Open in new window


exec [st_DailyEmail] 'john', 'aaa@aaa.com'

Open in new window

0
Pawan KumarDatabase ExpertCommented:
updated code ..Please try this -

USE [pdn]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[st_DailyEmail]
@user as varchar(50),
@email as varchar(50)
AS	
 
DECLARE @MAIL_BODY VARCHAR(8000) = ''
DECLARE @MAIL_BODY1 VARCHAR(8000) = ''
 
--/* HEADER */
SET @MAIL_BODY = 'HTML code here'
 
SET @MAIL_BODY1 = ''
SELECT @MAIL_BODY1 = @MAIL_BODY1 +  'code here' FROM tables
where convert(varchar(10),[ActivityDate],101) = convert(varchar(10),getdate(),101) and Assigned = @user

--IF @@ROWCOUNT > 0 
BEGIN
	  SET @MAIL_BODY = @MAIL_BODY + @MAIL_BODY1 + '</table>'
      EXEC msdb.dbo.sp_send_dbmail
	  @body_format='HTML',
      @profile_name = 'PDN',
      @recipients = @email,
	  @blind_copy_recipients = 'bbb@bbb.com;ccc@ccc.com',
      @subject = 'notification',
      @body = @MAIL_BODY
END

Open in new window

0
mcrmgAuthor Commented:
okay, in order to be easier to debug, I simplified the code. But for some reason, it is not working. Any ideas? (sorry)  thanks

USE [pdn]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[st_DailyEmail]
@user as varchar(50),
@email as varchar(50)
AS	
 
BEGIN
	  
      EXEC msdb.dbo.sp_send_dbmail
	  @body_format='HTML',
      @profile_name = 'PDN',
      @recipients = @email,
	  @blind_copy_recipients = 'bbb@bbb.com;ccc@ccc.com',
      @subject = 'notification',
      @body = 'this is a test'
END

Open in new window

0
Pawan KumarDatabase ExpertCommented:
What values you are passing in..
@user as varchar(50),
@email as varchar(50)
0
mcrmgAuthor Commented:
exec [st_DailyEmail] 'john', 'aaa@aaa.com'

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.