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! Best Practices: The Integrated Project and Portfolio Management Platform.

    Hear how IBM Rational Project and Portfolio Management integrated solutions help teams put the right tools and processes in place to maximize the effectiveness and efficiency of project teams and ensure that the business vision is being executed correctly. Learn how to automate and integrate requirements prioritization, top-down project planning, communications and controls, and methodology deployment to keep your scope, costs, and schedules under control. Tackle with an end-to-end approach the management of scope and scope changes, usage of methodology to control and empower project teams, and optimization of resources to align activity costs with the overall project plan.
    FREE! Go There Now!


    NEW! Best Practices in Integrated Requirements Management

    Poor Requirements Management capabilities in an Enterprise have been linked to excessive project failures, escalating IT costs, and failure to deliver competitive advantage into the marketplace. Join Brianna M Smith from IBM Rational and learn about how successful organizations align IT and Business stakeholders through collaborative processes and tools for effective requirements management, and how an integrated approach across the IT lifecycle can provide unparalleled visibility and traceability to ensure that project teams are delivering on the business vision by "doing the right things" and "doing things right."
    FREE! Go There Now!


    NEW! Cook up Web sites fast with CakePHP, Part 4: Use CakePHP&apos;s Session and Request Handler components

    CakePHP is a stable production-ready, rapid-development aid for building Web sites in PHP. This "Cook up Web sites fast with CakePHP" series shows you how to build an online product catalog using CakePHP.
    FREE! Go There Now!


    NEW! Discovering the value of WebSphere Process Server

    WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies.
    FREE! Go There Now!


    NEW! IBM Rational ClearCase Innovator's Series

    Learn from the best! Find out how developers use Rational ClearCase to be more flexible, innovative and deliver higher quality code in the Rational ClearCase Power Users eKit. This complimentary eKit provides a collection of materials, like articles, whitepapers, and demos that can help you become a power user of Rational ClearCase.
    FREE! Go There Now!


    NEW! Rational Asset Manager eKit

    Learn how to do more with your reusable assets with the free Rational Asset Manager eKit. The eKit includes demos on how Rational Asset Manager tracks and audits your assets in order to utilize them for reuse. Plus you’ll find white papers and a Webcast that discuss the challenges of a Service Oriented Architecture and how Rational Asset Manager can provide quick and effective solutions.
    FREE! Go There Now!


    NEW! Rational Modeling Extension for Microsoft.Net

    Rational Modeling Extension for Microsoft .NET enhances usability for code generation supporting a more intelligent refactoring. The latest enhancements enable organizations with Java and .NET systems and software development maintain architectural integrity across heterogeneous platforms.
    FREE! Go There Now!


    NEW! Webcast: Application security testing and Web compliance

    Join the IBM Watchfire team for an informative discussion on techniques and best practices to proactively manage Web application security and how to effectively build application security testing into the software development lifecycle (SDLC). In this Software Delivery Platform webcast you will learn: How to better understand potential web application security vulnerabilities, best practices and how to effectively integrate application security testing into the software development lifecycle, the importance of detecting and removing software vulnerabilities during application development.
    FREE! Go There Now!


    NEW! Whitepaper: Achieving consistency between business process models and operational guides

    Explore how Rational and WebSphere software enable enterprise documentation in SOA environments. Specifically, a new integration between IBM WebSphere® Business Modeler and IBM Rational® Method Composer software can help technical writers more easily keep enterprise operations manuals in sync with changes that are made to business processes, resulting in more accurate and timely documentation that benefits the entire enterprise.
    FREE! Go There Now!


    Refresh! IBM Rational Systems Development Solution eKit

    With IBM Rational Systems Development Solution, you can deliver products faster with higher quality. Within this kit, Read the “Model Driven Systems Development” white paper to see how to improve product quality and communication. Then check out the rest of the e-Kit to learn more about important topics that can affect the success of any software project through customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems. From start to finish, at every stage in your projects, Rational Systems Development Solution can help your company reach its full potential.
    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...
    - Various methods of setting Date values to a ...
    - 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...





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