Click here to Skip to main content
15,881,882 members
Articles / Web Development / ASP.NET

Send 1000s of Emails Without Timeout

Rate me:
Please Sign up or sign in to vote.
4.53/5 (18 votes)
13 Dec 2009CPOL2 min read 61.1K   2.8K   83  
Now you can send more than 1000 emails with a simple website and a process
CREATE TABLE [dbo].[NewsletterEmails]
(
	[Id] [int] IDENTITY(1,1) NOT NULL PRIMARY KEY,
	NAME [varchar](50) NULL,
	[Email] [varchar](50) NULL
)
GO

CREATE TABLE ProcessLog
(
	Id int PRIMARY KEY IDENTITY(1,1),
	StartDate datetime, 
	EndDate datetime, 
	EmailsSent int, 
	SendFailed int,
	LogFile varchar(max)
)
GO
CREATE PROCEDURE [dbo].[SendNewsletterMails]
(
	@Email varchar(max),
	@Body text,
	@Subject varchar(255)
)
as

EXEC msdb.dbo.sp_send_dbmail
@blind_copy_recipients=@Email,
@body= @Body, 
@subject = @Subject,
@body_format = 'HTML',
@profile_name = 'MyDBMail'

GO

-- configuring sql smpt email sender
USE msdb
GO

EXECUTE msdb.dbo.sysmail_add_account_sp
@account_name = 'MyAccount', @email_address = 'sender@provider.com', @display_name = 'sender name', @mailserver_name = 'localhost'

EXECUTE msdb.dbo.sysmail_add_profile_sp
@profile_name = 'MyDBMail' 

EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
@profile_name = 'MyDBMail', @account_name = 'MyAccount', @sequence_number = 1


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader IDS
Lebanon Lebanon
Adore programming, interested in workflows, SharePoint and silverlight, Entity Framework.
My Blog: http://suhamneimne.wordpress.com

Comments and Discussions