This is probably a simple problem but I just can't see it.
We have two tables, Login table and Notifications table.
Each time a user wishes to recover his or her password, the user opens up the app to the browser, enters his or her email address and clicks the Recover password button.
If the user does not exist on the database, a message is displayed to the user advising him or her that his or her account doesn't exist on our database. This works fine.
If the info exists s/he is supposed to receive an email containing his or her password. This is where the problem is.
The user is not receiving an email at all.
In the code below, user's info is extracted from login table and inserted into notifications table.
Then the Notifications table is queried and email sent out to users from this table.
Why are we doing it this way?
Because the database is outside our firewall and there is no way to send an email from the location of the app.
Our only option is to use dbmail.
My question is why isn't this stored procedure sending out email?
It only sends to me because my email address is hardcoded.
My code is below and your assistance is greatly appreciated.
ALTER PROCEDURE [dbo].[ForgorttenPWD]
@LoginEmail nvarchar(50) = ''
AS
BEGIN
SET NOCOUNT ON;
IF NOT EXISTS (SELECT 1 FROM [tblLogin]
WHERE email = @LoginEmail)
BEGIN
RAISERROR ('The email address you entered does not exist on our database. Please try another email address',16,1)
RETURN
END
INSERT into Notifications(mailContent, LoginId, FullName, email, Password, sender, Sent)
SELECT
'This is a computer generated email message.
Dear '+ FullName +':
Please check your Mail Box for the password..
Your UserName is: '+ email +'.
Your Password is: '+ password +',
LoginId,
FullName,
email,
Password,
'NoReply@myemail.com',
'No'
FROM [tblLogin]
WHERE email = @LoginEmail
ORDER BY LoginId DESC
Declare @email nvarchar(MAX),@content1 nvarchar(4000)
SELECT top 1 @email = @email+';'+Email, @content1 = mailcontent
FROM Notifications
WHERE sent = 'No' and email=@LoginEmail
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'The Registrations Office', -- defined email profile or static info
@recipients = @email, -- your email
@blind_copy_recipients = 'myemail@mycompany.com',
@subject = 'Your Account Details',
@body = @content1;
Update Notifications SET Sent = 'Yes' WHERE Sent = 'No'
END