Notitie
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen u aan te melden of de directory te wijzigen.
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen de mappen te wijzigen.
Van toepassing op:SQL Server op Linux
In dit artikel wordt beschreven hoe u Database Mail instelt en gebruikt met SQL Server Agent (mssql-server-agent) in Linux.
1. Database-e-mail inschakelen
USE master;
GO
EXECUTE sp_configure 'show advanced options', 1;
GO
RECONFIGURE WITH OVERRIDE;
GO
EXECUTE sp_configure 'Database Mail XPs', 1;
GO
RECONFIGURE;
GO
2. Een nieuw account maken
EXECUTE msdb.dbo.sysmail_add_account_sp
@account_name = 'SQLAlerts',
@description = 'Account for Automated DBA Notifications',
@email_address = 'sqlagenttest@example.com',
@replyto_address = 'sqlagenttest@example.com',
@display_name = 'SQL Agent',
@mailserver_name = 'smtp.example.com',
@port = 587,
@enable_ssl = 1,
@username = 'sqlagenttest@example.com',
@password = '<password>';
GO
Waarschuwing
Uw wachtwoord moet voldoen aan het standaard SQL Server-wachtwoordbeleid . Standaard moet het wachtwoord ten minste acht tekens lang zijn en tekens bevatten uit drie van de volgende vier sets: hoofdletters, kleine letters, basis-10 cijfers en symbolen. Wachtwoorden mogen maximaal 128 tekens lang zijn. Gebruik wachtwoorden die zo lang en complex mogelijk zijn.
3. Een standaardprofiel maken
EXECUTE msdb.dbo.sysmail_add_profile_sp
@profile_name = 'default',
@description = 'Profile for sending Automated DBA Notifications';
GO
4. Het Database Mail-account toevoegen aan een Database Mail-profiel
EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
@profile_name = 'default',
@principal_name = 'public',
@is_default = 1;
GO
5. Account toevoegen aan profiel
EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
@profile_name = 'default',
@account_name = 'SQLAlerts',
@sequence_number = 1;
GO
6. Test-e-mail verzenden
Mogelijk moet u naar uw e-mailclient gaan en de optie toestaan dat minder veilige clients e-mail verzenden inschakelen. Niet alle clients herkennen Database Mail als een e-maildemon.
EXECUTE msdb.dbo.sp_send_dbmail
@profile_name = 'default',
@recipients = 'recipient-email@example.com',
@subject = 'Testing DBMail',
@body = 'This message is a test for DBMail';
GO
7. Database Mail-profiel instellen met mssql-conf of omgevingsvariabele
U kunt het hulpprogramma mssql-conf of omgevingsvariabelen gebruiken om uw Database Mail-profiel te registreren. In dit geval noemen we ons profiel default.
Instellen via mssql-conf:
sudo /opt/mssql/bin/mssql-conf set sqlagent.databasemailprofile defaultInstellen via omgevingsvariabele:
MSSQL_AGENT_EMAIL_PROFILE=default
8. Een operator instellen voor sql Server Agent-taakmeldingen
EXECUTE msdb.dbo.sp_add_operator
@name = N'JobAdmins',
@enabled = 1,
@email_address = N'recipient-email@example.com',
@category_name = N'[Uncategorized]';
GO
9. E-mail verzenden wanneer agenttesttaak slaagt
EXECUTE msdb.dbo.sp_update_job
@job_name = 'Agent Test Job',
@notify_level_email = 1,
@notify_email_operator_name = N'JobAdmins';
GO