how to send email from SQL database. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how to send email from SQL database.

15th Dec 2016, 7:21 AM
Akwin Lopez
Akwin Lopez - avatar
2 Answers
0
USE [YourDB] EXEC msdb.dbo.sp_send_dbmail @recipients = '[email protected]; [email protected];[email protected]’ , @body = ' A warm wish for your future endeavor', @subject = 'This mail was sent using Database Mail' ; GO
15th Dec 2016, 7:21 AM
Akwin Lopez
Akwin Lopez - avatar
0
Step 1) Create Profile and Account You need to create a profile and account using the Configure Database Mail Wizard which can be accessed from the Configure Database Mail context menu of the Database Mail node in Management Node. This wizard is used to manage accounts, profiles, and Database Mail global settings. Step 2) RUN: sp_CONFIGURE 'show advanced', 1 GO RECONFIGURE GO sp_CONFIGURE 'Database Mail XPs', 1 GO RECONFIGURE GO Step 3) USE msdb GO EXEC sp_send_dbmail @profile_name='yourprofilename', @recipients='[email protected]', @subject='Test message', @body='This is the body of the test message. Congrates Database Mail Received By you Successfully.' To loop through the table DECLARE @email_id NVARCHAR(450), @id BIGINT, @max_id BIGINT, @query NVARCHAR(1000) SELECT @id=MIN(id), @max_id=MAX(id) FROM [email_adresses] WHILE @id<=@max_id BEGIN SELECT @email_id=email_id FROM [email_adresses] set @query='sp_send_dbmail @profile_name=''yourprofilename'', @recipients='''+@email_id+''', @subject=''Test message'', @body=''This is the body of the test message. Congrates Database Mail Received By you Successfully.''' EXEC @query SELECT @id=MIN(id) FROM [email_adresses] where id>@id END
15th Dec 2016, 7:24 AM
TechBeat
TechBeat - avatar