Ich sende Benachrichtigungs-E-Mail mit SQL Server, aber manchmal werden keine E-Mails an die Benutzer gesendet.Senden von E-Mail mit sp_send_dbmail() funktioniert manchmal nicht
Hier ist meine SQL-Tabelle, die ich E-Mails speichern, die es den Benutzern
CREATE TABLE [dbo].[EmailNotification](
[Id] [INT] IDENTITY(1,1) NOT NULL,
[EmailAdress] [NVARCHAR](50) NULL,
[EmailBody] [NVARCHAR](500) NULL,
[EmailSubject] [NVARCHAR](250) NULL,
[Attachment] [NVARCHAR](500) NULL,
[EmailSent] [BIT] NULL CONSTRAINT [DF_EmailNotification_EmailSent] DEFAULT
((0)),
[EmailCreateDate] [DATETIME] NULL CONSTRAINT
[DF_EmailNotification_EmailCreateDate] DEFAULT (GETDATE()),
[EmailSentDate] [DATETIME] NULL,
CONSTRAINT [PK_EmailNotification] PRIMARY KEY CLUSTERED
([Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
gesendet wird, und ich habe einen Job erstellt, die alle 1 Minute
CREATE PROCEDURE [dbo].[spSendEmail]
AS
BEGIN
BEGIN TRAN
DECLARE @id BIGINT
DECLARE @max_id BIGINT
DECLARE @query NVARCHAR(1000)
DECLARE @EmailBody NVARCHAR(1000)
DECLARE @EmailAdress NVARCHAR(500)
DECLARE @EmailSubject NVARCHAR(500)
DECLARE @attachments NVARCHAR(1000)
if exists (SELECT * FROM dbo.EmailNotification where EmailSent=0)
begin
SELECT @id=MIN(id) FROM dbo.EmailNotification where EmailSent=0
SELECT @EmailAdress=EmailAdress,@EmailBody=EmailBody,@EmailSubject=EmailSubject,@attachments=Attachment
FROM EmailNotification WHERE id = @id
exec [msdb].[dbo].[sp_send_dbmail] @profile_name='Notification',
@[email protected],
@blind_copy_recipients='example.email.com',
@[email protected],
@[email protected],
@[email protected]
end
IF(@@ERROR>0)
BEGIN
ROLLBACK
END
ELSE
BEGIN
UPDATE EmailNotification set EmailSent=1, EmailSentDate=getdate() WHERE [email protected]
COMMIT
END
„Funktioniert nicht ". Meinst du, sie erhalten die E-Mail nicht? Ändern Sie zunächst Ihren Code und notieren Sie sich den Rückgabewert wie unten beschrieben. Dann überprüfen Sie die SQL-Protokolle zu sehen, ob es einen Fehler erwähnt –