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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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!


    IBM – Taking Web 2.0 to Work

    You'll get answers to many questions and more from David Barnes, Lead Evangelist for IBM Emerging Internet Technologies. David will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve.
    FREE! Go There Now!


    NEW! Download IBM WebSphere Portal V6.1 beta code

    Download the IBM WebSphere Portal V6.1 beta code and learn more about the rich features and enhancements in IBM WebSphere Portal V6.1. WebSphere Portal provides a composite application or business mashup framework and the advanced tooling needed to build flexible, SOA-based solutions, and scalability to meet the needs of any size organization.
    FREE! Go There Now!


    NEW! Evaluate IBM Lotus Sametime Standard V8.0

    Visit IBM developerWorks to download a free trial of the latest release of IBM Lotus Sametime Standard V8.0. Lotus Sametime Standard V8.0 is a platform for unified communications and collaboration that combines security features with an extensible, open solution including integrated Voice over IP, geographic location awareness, mobile clients, and a robust Business Partner community offering telephony and video integration.
    FREE! Go There Now!


    NEW! Evaluate Rational Host Access Transformation Services (HATS) Toolkit V7.1

    Visit IBM developerWorks to download a free trial of the Rational Host Access Transformation Services (HATS) Toolkit. The HATS toolkit provides a set of plug-ins for the IBM Rational Software Delivery Platform to help you easily extend your legacy applications. HATS makes your 3270 and 5250 applications available as HTML through the most popular Web browsers, while converting your host screens to a Web look and feel and it also enables you to develop new Web, portal, and rich-client applications.
    FREE! Go There Now!


    NEW! Hello World: Learn how to install and use the Rational Asset Manager Eclipse client

    In this tutorial, you can learn how to install and configure the IBM Rational Asset Manager Eclipse client, explore the different views in the Asset Management perspective, learn various search techniques, work with existing assets, and submit a new asset.
    FREE! Go There Now!


    NEW! The dirty dozen: preventing common application-level hack attacks

    As organizations have grown increasingly dependent on online software, the risk of malicious attacks has also become far more serious. Fortunately, well-governed organizations can protect their Web applications by injecting vulnerability assessments and ethical hacks into their software development and delivery processes. This paper describes 12 of the most common hacker attacks and provides basic rules that you can follow to help create more hack-resistant Web applications.
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Tester for SOA Quality V7.0.1

    Get a free trial download of the latest version of IBM Rational Tester for SOA Quality V7.0.1, a functional and regression testing tool that enables the creation, comprehension, modification and execution of testing GUI-less Web services.
    FREE! Go There Now!


    NEW! Understanding Web application security challenges

    As businesses grow increasingly dependent upon Web applications, these complex entities grow more difficult to secure. Most companies equip their Web sites with firewalls, Secure Sockets Layer (SSL), and network and host security, but the majority of attacks are on applications themselves – and these technologies cannot prevent them. This paper explains what you can do to help protect your organization, and it discusses an approach for improving your organization’s Web application security.
    FREE! Go There Now!


    NEW! Webcast: Striking the right balance between manual and automated testing

    Join this webcast to learn how IBM Rational's Functional Testing solution enables you to implement automation your way, at your pace, with your existing staff. In this webcast, you’ll learn how you can eliminate redundancy of manual test scripts, reduce errors, and increase test coverage through test automation. After this presentation you will understand how IBM Rational Functional Testing solution can streamline your manual testing and make test automation easily attainable.
    FREE! Go There Now!


    NEW! Webcast: 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!



    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...

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT