ASP Code
  Home arrow ASP Code arrow Send e-mails to multiple recipients using ...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP CODE

Send e-mails to multiple recipients using addresses from a database
By: aspfree
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 17
    2000-08-24

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT



    Updated: 01/11/2000 - I have had quite a few amendments sent to me on this article (it's good to see that people aren't simply copying it word for word). Now the code should run more smoothly and has been further tested with the CDONTS method. Thanks to Chris Knipe and Todd Taylor amongst others. Last of all, I will soon be creating a new script that sends the e-mails separately so recipients cannot see eachothers e-mail addresses. If anyone has any ideas please feel free to e-mail me, your name will be displayed as a contributor.

    This article will show you how to place variables into an array and from that array, add each recipient to an e-mail. If you do not have much experience in using the CDONTS mail component or the AspMail component please learn the basics before you read this article. Please change the text in the red writing. If you do have any questions about any other ASP or WAP/WML related problems please feel free to e-mail me at michael_wright@lineone.com and if you are a Manager, Supervisor or Director please feel free the offer me a job.

    So here’s the code:

    '-----------------------------------------

    'Multiple-newsletter e-mailer using database

    'Language: VBscript

    'Date: 21/08/2000

    'Author: Michael Wright

    '-----------------------------------------

    'THIS SCRIPT WILL FIRST STORE THE E-MAIL NAMES INTO

    'AN ARRAY FROM AN MS ACCESS DATABASE.

    'INITIALISE VARIABLES AND SET OBJECTS

    dim conn

    dim rs

    dim strsql

    dim strconn

    strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("LOCATION OF DATABASE")

    set conn = server.createobject("adodb.connection")

    conn.open strconn

    set rs = server.createobject("adodb.recordset")

    'SET COUNTER VARIABLE TO 0

    intCount = 0

    'CHANGE SQL TO YOUR OWN DATABASE TABLES

    Query = "SELECT EmailAddressField FROM Database1 SORT BY ID"

    'OPEN AND CONNECT TO DATABASE, QUERY DATABASE

    rs.open Query, conn

    'debug: Response.Write(Query)

    if not rs.eof Then

    rs.movefirst

    Do While NOT rs.EOF

    'INCREMENT COUNTER

    intCount = intCount + 1

    'PLACE RECORDSET INTO ARRAY

    Emails = rs.getrows()

    rs.movenext

    Loop

    else

    response.write("No records found.")

    end if

    'CLOSE RECORDS AND SET OBJECTS TO NULL

    rs.close

    set rs= nothing

    set conn = nothing

    set strconn = nothing

    Now it’s time to create the e-mail, add the addresses from the array and then send it. If you have the AspMail component active on your system use the script below but if you would prefer to use the CDONTS component then use the script after.

    Set Mailer = CreateObject("SMTPsvg.Mailer")

    'ADD YOUR SMTP MAILSERVER LOCATION

    Mailer.RemoteHost = "MAILSERVER LOCATION"

    'ADD WHO YOU WANT THE SENDER TO BE E.G.

    'website@aarogya.com

    Mailer.FromAddress = "FROM ADDRESS"

    'THIS ADDS ALL THE RECIPENTS TO THE EMAIL

    If intCount <> 0 Then

    Do While i <> intCount

    'CHANGE THE FIRST DIMENSION OF THE ARRAYS TO SUIT YOUR

    'DATABASE BUT IT SHOULD BE A FIELD NUMBER E.G. 0 THE FIRST FIELD

    Mailer.AddRecipient Emails(FIELD OF RECIPENTS NAME,i), Emails(FIELD OF RECIPENTS EMAIL

    ADDRESS,i)

    i = i + 1

    Loop

    Else

    Mailer.AddRecipient "YOUR OWN NAME", "YOUR OWN ADDRESS"

    End If

    Mailer.Subject = "YOUR E-MAILS SUBJECT"

    'PLACE YOUR OWN EMAIL MESSAGE HERE

    Mailer.BodyText = "YOUR E-MAILS BODY TEXT"

    'SEND EMAIL

    If Mailer.SendMail Then

    Response.Write "Mail has been sent..."

    else

    Response.Write "Mail send failure. Error was " & Mailer.Response

    end if

    'SET MAILER TO NOTHING

    Set Mailer = nothing

    'END OF SCRIPT

     

    Here is the code for the CDONTS method of the above.

     

    'Declare local variables to hold the data from the Input form page that is used above.

    Dim strTo

    Dim strSubject,

    Dim strBody 'Strings for recipient, subject, boby

    Dim objCDOMail 'The CDO object

    ' Create an instance of the NewMail object.

    Set objCDOMail = Server.CreateObject("CDONTS.NewMail")

    ' Set the properties of the object

    objCDOMail.From = "YOUR FROM ADDRESS"

    objCDOMail.To = "YOUR TEST ADDRESS TO CHECK E-MAIL HAS BEEN SENT"

    'THIS ADDS ALL THE RECIPENTS TO THE EMAIL
    strEmailStart = ""
     
    IF intCount <> 0 THEN
      Do While i <> intCount
      'CHANGE THE FIRST DIMENSION OF THE ARRAYS TO SUIT YOUR DATABASE BUT IT SHOULD BE A FIELD NUMBER E.G. 0 THE FIRST FIELD
      strEmailStart = strEmailStart & strToEmail(FIELD OF RECIPENTS EMAIL ADDRESS,i) & ";"
      i = i + 1
      Loop
    ELSE
      objCDOMail.Cc = "myemail@email.com"
    END IF
     
    'debug: Response.Write strEmailStart
    objCDOMail.Cc = strEmailStart

    objCDOMail.Subject = "YOUR E-MAILS SUBJECT"

    objCDOMail.Body = "YOUR E-MAILS BODY TEXT"

    ' There are lots of other properties you can use.

    ' You can send HTML e-mail, attachments, etc...

    ' You can also modify most aspects of the message

    ' like importance, custom headers, ...

    ' Check the help files for a full list as well

    ' and the correct syntax.

    ' Some of the more useful ones I've included samples of here:

    'objCDOMail.Cc = "mailto:sschofield@aspfree.com;steve@aspfree.com" Notice this sending to more than one person!

    'objCDOMail.Bcc = "sschofield@aspfree.com;steve@aspfree.com"

    'objCDOMail.Importance = 1 '(0=Low, 1=Normal, 2=High)im a

    'objCDOMail.AttachFile "c:\path\filename.txt", "filename.txt"

    ' Send the message!

    objCDOMail.Send

    'Set the object to nothing because it immediately becomes

    'invalid after calling the Send method + it clears it out of the Server's Memory.

    Set objCDOMail = Nothing

    The array code and one of the e-mail pieces of code should be place into an .asp file and then when opened within a web browser the newsletter you created will be on it's way to the specified recipients providing you have changed the BODY TEXT fields to display your newsletters message. I am sorry about the code not being incremented, but when I used MS Word to convert it to HTML they disappeared.

    I hope this article has been of some use to you.

     


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More ASP Code Articles
    More By aspfree

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Accelerating Software Innovation on i on Power Systems

    Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, for an overview of Rational’s new software offerings and resources to help modernize and accelerate software innovation on i on Power Systems – while ensuring past application investments are protected and continue to grow. Learn how these solutions are helping customers extend their core i5/OS solutions toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time.
    FREE! Go There Now!


    NEW! Develop Systems Software Assets with IBM Rational Asset Manager

    Join us for this on demand webcast to learn about developing complex systems more quickly and efficiently. We'll cover market drivers for developing, governing and reusing systems software assets and how you can develop system software assets with Rational Asset Manager.
    FREE! Go There Now!


    NEW! Download DB2 Express-C 9.5

    Visit IBM developerWorks to download IBM DB2 Express-C 9.5, a no-charge version of DB2 Express 9 database server. DB2 Express-C offers the same core data server base features as other DB2 Express editions and provides a solid base to build and deploy applications developed using C/C++, Java, .NET, PHP, and other programming languages.
    FREE! Go There Now!


    NEW! Evaluate IBM Rational Developer for System i V7.1

    Download a free trial version of IBM Rational Developer for System i V7.1, which provides a complete development environment for traditional i5/OS application development. IBM Rational Developer for System i is a new eclipse-based workstation offering for i5/OS application development that provides a comprehensive Integrated Development Environment for edit/compile/debug of traditional RPG/COBOL/C/C++ i5/OS applications.
    FREE! Go There Now!


    NEW! IBM Rational Systems Development e-Kit

    As systems increase in complexity, communication between systems and software teams becomes more and more difficult. Now, there’s a way to improve product quality and communication.<br />Read the “Model Driven Systems Development” white paper to see how. Also included in this kit are more educational white papers, customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems.<br />
    FREE! Go There Now!


    NEW! Improve your build process with IBM Rational Build Forge, Part 1: Create a continuous build and integration environment

    Learn how to implement a build management system that uses and extends your existing automation technologies. This tutorial shows, step-by-step, how to install and configure IBM Rational Build Forge to manage builds for Jakarta Tomcat from source code.
    FREE! Go There Now!


    NEW! Rational Talks to You: Grady Booch on Architecture

    Join this Rational Talks to You teleconference on November 29 at 1:00 pm ET to participate in an interactive discusssion with Grady Booch around architecture and reuse. Get your questions answered!
    FREE! Go There Now!


    NEW! Rational Testing eKits

    Discover how Rational tools and best practices for testing can make your job easier. The new Rational Testing eKits provide you with valuable resources – including demos, webcasts, tutorials, and articles – that help you address your specific testing needs across the software lifecycle. Five new eKits are available covering the topics of Requirements and Test Management, Functional Testing, Performance Testing, Code Quality and Embedded Systems, and SOA and Web Services Testing.
    FREE! Go There Now!


    NEW! Successful Change and Release Management for .NET

    Join this webcast to discover the key requirements for successful change and release management. Learn how to extend your .NET environment to improve productivity and collaboration, and address core problems afflicting team development. In this webcast, we’ll review typical challenges faced by customers and how to resolve them with the IBM Rational Change and Release Management solution, including Rational ClearCase, Rational ClearQuest and Rational Build Forge. Replay is available for 9 months.
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Functional Tester V7.0.1

    Get a free trial download of the latest version of IBM Rational Functional Tester V7.0.1. Rational Functional Tester is an automated functional and regression testing solution for QA teams concerned with the quality of their Java, Microsoft Visual Studio .NET, and Web-based applications.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    ASP CODE ARTICLES

    - ASP Forms
    - ASP: The Beginning
    - Getting Remote Files With ASP Continued
    - Inbox and Outbox Manipulation in ASP
    - Relational DropDownList Using VB.NET
    - Ad Tracking URL Hits
    - Use ViewState to display one record per page...
    - Send Email using ASP.NET formatted in HTML
    - ASP File Explorer
    - ASP/XML Interview questions by Srivatsan Sri...
    - Conditional DataGrid Item and using checkbox...
    - Fill .NET Listbox with SQL DataReader
    - Filling Dropdown box using Code-Behinds in C#
    - FLAMES code sample written in .NET What is F...
    - Format Date/Time in a console app class





    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek