Script to send emails

Script to send emails

Postby Daniel » Wed Jul 03, 2013 9:03 am

I have been using the following function in several of my ConnectR scripts if I need to send an email other than one of the built in notifications. You'll have to add logic to the script to define who the recipients are, what the subject and message should be, and some other logic to determine conditions to send the message. Thought I would post it here for anyone else who may want to use it.

Your ConnectR server will have to be set up to allow outbound traffic on port 25 and make sure to set the SMTP server in the script to the name of your organization's email server.

Code: Select all
Function sendMail(from, recipientList, ccList, bccList, subject, message)
    Dim CDO_Mail_Object
    Dim CDO_Config
    Dim SMTP_Config
    Set CDO_Mail_Object = CreateObject("CDO.Message")
    Set CDO_Config = CreateObject("CDO.Configuration")
    CDO_Config.Load -1
    Set SMTP_Config = CDO_Config.Fields
    With SMTP_Config
        .Item("") = 2
        .Item("") = "EMAILSERVER"
        .Item("") = 25
    End With
    With CDO_Mail_Object
        Set .Configuration = CDO_Config
    End With
    CDO_Mail_Object.from = from
    'To have multiple recipient, cc, or bcc addresses, use a semicolon
    'separated list of addresses in the corresponding variable below
    'Example:  ";;" = recipientList = ccList
    CDO_Mail_Object.BCC = bccList
    CDO_Mail_Object.subject = subject
    CDO_Mail_Object.TextBody = message
    'File attachment if necessary
    'CDO_Mail_Object.AddAttachment FileToAttach
    'Send the message

End Function
Posts: 5
Joined: Thu Mar 01, 2012 1:39 pm

Return to Tools: Queries, Scripts

Who is online

Users browsing this forum: No registered users and 1 guest