p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   VBScript (http://p2p.wrox.com/forumdisplay.php?f=77)
-   -   send emails to several users (http://p2p.wrox.com/showthread.php?t=28111)

femig April 14th, 2005 01:43 AM

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?

mmcdonal April 15th, 2005 06:25 AM

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.


femig April 15th, 2005 07:33 AM

can you post the code please?

mmcdonal April 15th, 2005 07:41 AM

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 & ")"

    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


    '==End remote SMTP server configuration section==


    MsgBox stFinished

End Sub


mmcdonal April 15th, 2005 07:42 AM

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


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

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