I have a problem setting up email notifications in SQL Server 2008.
I am using SQL Server 2008 to build a data cube. This process consists of several jobs, that are all scheduled to run each night at a specific time. To see whether a job was running without any failure, it is possible to set up email notification.
(source: smilinginthesun.de)
(source: smilinginthesun.de)
Unfortunately, no email is sent even though I think I have set up database mail correctly.
All guides I can found just explains, how to set up database mail (eg. http://blog.sqlauthority.com/2008/08/23/sql-server-2008-configure-database-mail-send-email-from-sql-database/), but thats it.
If I sent a mail to test functionality (via test email button or from T-SQL script) it works just fine and the email arrives. But when using the notification feature in a job, it doesn't even create a sysmail_mailitems or sysmail_log entry.
I have also send an email using sp_notify_operator, successfully. So the operator set up seems to work, too. (Thanks, Joe Stefanelli, for the hint.)
There is a great workaround written for SQL Server 2005, that works for me, too: http://www.howtogeek.com/howto/database/sending-automated-job-email-notifications-in-sql-server-with-smtp/, but why isn't it possible to just use that build-in functionality?
Does anyone knows if there is anything else to do, to make that email notification task work properly? Thanks in advise.
I am late but I saw your post having the same problem.
The solution is to enable a mail profile for alerts.
For this:
Right click on "SQL Server Agent"
Then "Properties".
Then go to "Alert System" section.
Tick the "Enable mail profile" box.
Then "OK".
Restart the SQL Server Agent service.
To send email notifications from agent jobs in SQL Server Agent, the alarm system must be activated. We did that. After restarting the agent, the Database Mail system should be used. Unfortunately, this does not work. The agent was still trying to reach a Mapi profile (as in SQL 2000).
The following registry value wasn't set: "UseDatabaseMail"=dword:00000001
After setting it to 1, the database mail system was used.
You can do that in SQL server, directly:
EXEC master.dbo.xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'UseDatabaseMail', N'REG_DWORD', 1
I've tried what ZeuG. indicated and still didn't have success... then I restarted the SQL Agent. That's what made the job email notification work for me.
For me, SQL email worked fine when I right-clicked Database Mail and said Send Test Email. However, after setting up alerts for all severities and running RAISERROR (N'Test alert!', 20, 1) WITH LOG;, no email came through. The issue is the service account that SQL Server Agent runs under. Apparently, the virtual account NT Service\SQLSERVERAGENT (or whatever your default may be) does not have permissions to access objects on the network and this includes e-mail.
To fix, change the service to use a local account under the Users group, restart SQL Server agent, and then try running a command that throws an error like the RAISERROR statement above. You should now receive the email.
Related
I have a strange one for you. I'm maintaining several databases prior to a migration. One of them is a 2008R2 instance. This instance has multiple errors in the logs (the infrastructure has been poorly maintained), so I set up a bunch of alerts (16-25) and tried using Database Mail to send them. But the mail registry settings keep resetting and preventing it from working. I can't tell if someone is maliciously going in behind me and reverting the settings in the registry (this is possible in the poisonous environment I'm working in) or whether it's some kind of obscure problem.
Just to confirm... I've created the same alerts with the same mail settings on the 2017 instances that I'm also monitoring with no problem. Equally, on the 2008R2 instance, I can successfully set the Database Mail parameters, send myself a test email AND execute a job, sending a 'completed' email using the same Database Mail profile and user via an Operator.
Setting the parameters using xp_instance_regwrite or sp_set_sqlagent_properties didn't work either, although I realised early on that the parameters weren't sticking because of a lack of admin rights on the server, so I got the infrastructure guys to give me access. I then:
logged in to the server
shut down the Agent (it isn't doing anything at all)
configured the registry settings (HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_50.<instance>\SQLServerAgent\UseDatabaseMail = 1, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_50.<instance>\SQLServerAgent\DatabaseMailProfile = <my-mail-profile>)
restarted the Agent.
I then confirmed from SSMS that the 'Mail session' parameters (Enable mail profile, Mail system and Mail profile) were correctly set. A day later, the log is full of errors, I have no emails and all of the Agent properties are empty and greyed out!
Anyone seen this before?
We are running into a few issues with our TFS installation (TFS 2013 Update 4, SQL 2014 Standard) as a result of email alerts. Most notably, Work Items cannot be created, because this triggers an email.
Any time a process or user attempts to create a Work Item, the error
TF30040: The database is not correctly configured. Contact your Team Foundation Server administrator.
is received. Further, when I check the Event Viewer on the server, I can see the error and it reports that the inner exception is:
Exception Message: The EXECUTE permission was denied on the object 'sp_send_dbmail', database 'msdb', schema 'dbo'. (type SqlException)
I have worked with the DBA and we have enabled Email Alerts on the server. We have verified that, in general, the alerts work by using the test button on the administration console. I can also set up a check-in alert through the web interface and receive said alerts without issue. This seems to be specifically affecting Work Item creation alerts (which apparently are just automatically and irrevocably enabled).
Presumably, we could correct this by giving appropriate permissions to use that stored procedure. To do so, we need to know what user to give permissions to. So far we have tried giving execute permissions to my AD user, the service account used by the build service, and the Network Service account (which appears to be the TFS Service Account).
There is no indication in any error message as to what user is being used to execute that procedure. So, my question: What SQL user is used to send alerts when creating Work Items?
Edit:
For the record, this started working of its own accord. We decided Monday to call Microsoft to get this fixed. Before that happened, failed builds magically created some work items (on Tuesday, a full day after we gave up), and we are now able to create work items. Everyone involved states not doing anything. We are baffled, but in a good way.
I'm going to advise you that a DBA should not be making changes to the TFS databases. I suggest opening a ticket with MSFT and getting assistance from the product support group.
So, I never expected to spend 6 hours trying to get Send DBMail working on SQL Server 2012, but here we are.
I'm trying to simply set up an SMTP server to use with Database Mail. I've tried both Verizon and Google. I've tested the settings in Thunderbird, and yet I still receive the following error:
10/31/2013 14:56:30,,Error,The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 1 (2013-10-31T14:56:30). Exception Message: Cannot send mails to mail server. (The operation has timed out.).),7084,6932,6038,,10/31/2013 2:56:30 PM,sa
This is getting ridiculous, I've scoured the web for similar issues and solutions, and found lots of ideas that didn't work. I even started an clean AWS instance with Server 2012 and it has the same problem. I've disabled Windows Firewall and Defender, and honestly I'm stumped and frustrated.
If you have access to add a role to your server then I would add the TELNET client for smtp testing. Test your smtp config using the following TELNET commands:
C:/>TELNET <mail server> 25
EHLO <mail server>
<IF AUTH REQUIRED ENTER CREDENTIALS>
MAIL FROM:<any account#yourdomain.com>
RCPT TO:<where you want mail to go #domain.com>
DATA
<ENTER>
<MESSAGE>
<PRESS PERIOD(".")>
If you do not get errors in telnet and/or the logs then Database Mail should work fine using MAIL SERVER. You need to set up a profile and mail account in sqlserver but the wizard is straight forward. Next, add a few operators with valid email addresses and you should receive your notifications.
So after much stress, and trying a different server/version, I found that MailJet worked flawlessly, and I'm back up and running.
I think Steoleary is on to something that somewhere along the line, the connection is being silently blocked. Either way, for anyone who runs into this problem, try another mail server, and another one, and another one.
My guess is the database mail feature is acting as a relay, and Verizon and Gmail are blocking it.
I've created a Database Mail account (tested and sends with no problem), created an operator, set up an alert on the job I want to monitor, and restarted my SQL Server Agent. But I still am not alerted when the job in question completes. Is there a step that is missing?
Look at your Database Mail log and make sure you don't have any errors sending there. Make sure your internal relay mail servers allow sending from the SQL server's IP address. Also run EXEC msdb.dbo.sysmail_help_status_sp and make sure the dbmail queue status is "Started" or "Receives_Occuring". If the queue is in a Stopped status, restart it with EXEC msdb.dbo.sysmail_stop_sp and EXEC msdb.dbo.sysmail_start_sp
Open the job, go to notifications and select Email, choose the operator you created, and the condition "When the job fails". That should do it.
Was able to get notifications to start sending after a server restart
When I use the sp_send_dbmail stored procedure, I get a message saying that my mail was queued. However, it never seems to get delivered. I can see them in the queue if I run this SQL:
SELECT * FROM msdb..sysmail_allitems WHERE sent_status = 'unsent'
This SQL returns a 1:
SELECT is_broker_enabled FROM sys.databases WHERE name = 'msdb'
This stored procedure returns STARTED:
msdb.dbo.sysmail_help_status_sp
The appropriate accounts and profiles have been set up and the mail was functioning at one point. There are no errors in msdb.dbo.sysmail_event_log.
Have you tried
sysmail_stop_sp
then
sysmail_start_sp
I had the same problem and this is how I was able to resolve it.
Go to Sql Agent >> Properties >> Alert System >> Check the Enable box for DBMail and add a profile.
Restart Agent and it works since then.
Hope this helps,
_Ub
Could be oodles of things. For example, I've seen (yes, actually seen) this happen after:
Domain controller reboot
Exchange server reboot
Router outage
Service account changes
SQL Server running out of disk space
So until it happens again, I wouldn't freak out over it.