Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Other Programming > VBScript
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
VBScript For questions and discussions related to VBScript.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 14th, 2005, 01:43 AM
Registered User
 
Join Date: Jan 2005
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default send emails to several users

i have a list of users in a database whom i want to send emails to
can anyone send me sample code on how to do this?
thanks

Reply With Quote
  #2 (permalink)  
Old April 15th, 2005, 06:25 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Sending emails in your script is easy. What data do you have on your users in the database? You need to call the database with the user info, and I am assuming gather thier email addresses, and then package your email and send it.

What is initiating this process? Is it automatic, or some database event (your database might already have an email feature) or a button or script initiation?

I have a button in one of my databases that packages data, and then emails it to several people to initiate a Help Desk process involving client assets. I have others. I am sure we could build someting for you.


mmcdonal
Reply With Quote
  #3 (permalink)  
Old April 15th, 2005, 07:33 AM
Registered User
 
Join Date: Jan 2005
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

can you post the code please?

Reply With Quote
  #4 (permalink)  
Old April 15th, 2005, 07:41 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

This should work to package data from your database and send it. If you need to get user info like email addresses as well, send me some table structure and we can rewrite the code.

'=====
Private Sub btnSendEmail_Click()

    Dim stSubject As String
    Dim stName As String
    Dim stSender As String
    Dim stMessage As String
    Dim stHelpDesk As String
    Dim stFinished As String
    Dim rs As ADODB.Recordset
    Dim stSQL As String
    Dim stAsset As String
    Dim stSN As String
    Dim stList As String

    stSQL = "Select * from qryAssets Where UserID = " & Me.UserID
    stSubject = "Exiting Employee"
    stSender = "OurUserName@OurDomain.gov"
    stName = Me.FirstName & " " & Me.LastName & " (" & Me.LOGIN_NAME & ")"
    stMessage = "Please retrieve the following items from "
    stHelpDesk = "Helpdesk@OurDomain.gov;HelpDeskManager@OurDomain. gov;AssetManager@OurDomain.gov"
    stFinished = "The HelpDesk has been notified."

    Set rs = New ADODB.Recordset
    rs.Open stSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic

    Do Until rs.EOF
        stAsset = rs!AssetCategory
        stSN = rs!SerialNumber
        stList = stList & vbCrLf & stAsset & " (SN:" & stSN & ")"
        rs.MoveNext
    Loop

    Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
    Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).

    Const cdoAnonymous = 0 'Do not authenticate
    Const cdoBasic = 1 'basic (clear-text) authentication
    Const cdoNTLM = 2 'NTLM

    Set objMessage = CreateObject("CDO.Message")
    objMessage.Subject = stSubject
    objMessage.Sender = stSender
    objMessage.To = stHelpDesk
    objMessage.TextBody = stMessage & stName & ":" & vbCrLf & stList

    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

    'Name or IP of Remote SMTP Server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.aoc.gov"

    'Type of authentication, NONE, Basic (Base64 encoded), NTLM
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic

    'Your UserID on the SMTP server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "****"

    'Your password on the SMTP server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "****"

    'Server port (typically 25)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

    'Use SSL for the connection (False or True)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False

    'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

    objMessage.Configuration.Fields.Update

    '==End remote SMTP server configuration section==

    objMessage.Send

    MsgBox stFinished

End Sub
'=====

mmcdonal
Reply With Quote
  #5 (permalink)  
Old April 15th, 2005, 07:42 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Sorry, that should be "mail.OurDomain.Gov", not mail.aoc.gov. That is an old reference.

mmcdonal
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sending emails for all users in the domain arabuafef ASP.NET 1.0 and 1.1 Basics 6 December 6th, 2006 10:51 AM
Code to send emails maitias C# 2005 2 February 1st, 2006 01:09 PM
Send two emails instead of one ss2003 Beginning PHP 3 January 28th, 2005 11:54 AM
Send Emails in ASP tdaustin Classic ASP Basics 4 August 12th, 2004 07:09 PM
Send Emails and Attachments. mistry_bhavin General .NET 2 August 11th, 2004 10:05 AM



All times are GMT -4. The time now is 06:53 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.