EXECUTE msdb.dbo.sysmail_add_account_sp
@account_name = 'Mail',
@description = 'Sent Mail using MSDB',
@email_address = 'server1@provider.com',
@display_name = 'Server 1',
@port = 587,
@enable_ssl = 1,
@username='michal@provider.com',
@password='P@sswOrd',
@mailserver_name = 'smtp.service.com'
EXECUTE msdb.dbo.sysmail_add_profile_sp
@profile_name = 'Mail',
@description = 'Profile used to send mail'
EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
@profile_name = 'Mail',
@account_name = 'Mail',
@sequence_number = 1
EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
@profile_name = 'Mail',
@principal_name = 'public',
@is_default = 1 ;
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Database Mail XPs', 1;
GO
RECONFIGURE
GO
exec msdb.dbo.sp_send_dbmail @profile_name = 'Mail', @recipients = 'michal@sqlfolks.com',
@subject = 'Mail Test', @body = 'Mail Sent Successfully', @body_format = 'text'
