in

Community Server

The platform that enables you to build rich, interactive communities

email all

Last post 03-05-2010 2:47 PM by drizzt09. 22 replies.
Page 1 of 2 (23 items) 1 2 Next >
Sort Posts: Previous Next
  • 09-07-2009 4:52 AM

    • drizzt09
    • Top 10 Contributor
    • Joined on 08-22-2009
    • Ontario Canada
    • Posts 399

    email all

    A function for admin to email a message to all users

  • 09-08-2009 7:27 PM In reply to

    Re: email all

    I modified the Edit News page to do just that.  I chose to allow for full HTML email to be sent from the news section, but if I wanted to only allow text emails then it would have probably only required a single line of code.  Also, if I was Mike and I was making this modification I probably would have modified every call to the SendMail function to have an optional extra variable passed, and if that variable is null then send a text email and if it is populated send a HTML email, but since I'm not Mike I just duplicated the SendMail function in email.asp and added one line to it (note that I have the GoDaddy modified SendMail function, but I bolded the changed lines):

    function SendHtmlMail(toAddr, subjectText, bodyText, htmlBody)
        dim mailer
        dim cdoMessage, cdoConfig
        'Assume all will go well.
        SendHtmlMail = ""
        'Configure the message.
        set cdoMessage = Server.CreateObject("CDO.Message")
        set cdoConfig = Server.CreateObject("CDO.Configuration")
        cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "relay-hosting.secureserver.net"
        cdoConfig.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "relay-hosting.secureserver.net"
        cdoConfig.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        cdoConfig.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        cdoConfig.Fields.Update
        set cdoMessage.Configuration = cdoConfig
        'Create the email.
        cdoMessage.From     = "Eric Wikman <eric@example.com>"
        cdoMessage.To       = toAddr
        cdoMessage.Subject  = subjectText
        cdoMessage.HTMLBody = htmlBody
        cdoMessage.TextBody = bodyText
        'Send it.
        on error resume next
        cdoMessage.Send
        'If an error occurred, return the error description.
        if Err.Number <> 0 then
            SendHtmlMail = Err.Description
        end if
        'Clean up.
        set cdoMessage = Nothing
        set cdoConfig  = Nothing
    end function

    and then modify editNews.asp to look like:

         sub SendNotifications()

            dim subj, body, htmlBody
            dim list, email

            subj = "Football Pool News Notification"
            body = "The site news has been updated." & vbCrLf _
                 & "Please visit " & POOL_URL & " for more information." & vbCrLf
            htmlBody = Request.Form("newContent") & vbCrLf & "<p>" & "Please visit <a href=""" & POOL_URL & """>" & POOL_URL & "</a> for more information.</p>"

            list = GetNotificationList("NotifyOfNewsUpdates")
            for each email in list
                call SendHtmlMail(email, subj, body, htmlBody)
            next

        end sub %>

  • 09-08-2009 7:36 PM In reply to

    Re: email all

     That's actually a good idea (plain tex or html email option). I'll keep it in mind for the next revision.

    Thanks for sharing the code btw. You folks are coming up with a lot of good ideas.

  • 09-09-2009 6:12 AM In reply to

    Re: email all

    I've changed the email.asp to send all messages as HTML by changing the following:

      'Create the email.
      cdoMessage.From     = "Football Pool" & " <" & ADMIN_EMAIL & ">"
      cdoMessage.To       = toAddr
      cdoMessage.Subject  = subjectText
      cdoMessage.HTMLBody = bodyText

    And then I added the HTML formatting to the editNews.asp file:

    <% '**************************************************************************
     '* Local functions and subroutines.                                       *
     '**************************************************************************

     '--------------------------------------------------------------------------
     ' Sends an email notification to any users who have elected to receive
     ' them.
     '--------------------------------------------------------------------------
     sub SendNotifications()

      dim subj, body
      dim sql, rs
      dim email

      subj = PAGE_TITLE & " - News Update Notification"
      body = "<html><head><link rel=""stylesheet"" type=""text/css"" href=""http://www.YOURHOST.com/YOURPOOL/styles/common.css"" /></head>" & VbCrLf _
        & "<body>" & VbCrLf _
        & "<table id=""wrapper"" align=""center""><tr><td>" & VbCrLf _
        & "<table class=""main newsletter"" cellpadding=""0"" cellspacing=""0"">" & VbCrLf _
        & "<tr class=""header bottomEdge"">" & VbCrLf _
        & "<th align=""left"">Football Pool News Update</th>" & VbCrLf _
        & "</tr>" & VbCrLf _
        & "<tr>" & VbCrLf _
        & "<td class=""freeForm"">" & VbCrLf _
        & news & VbCrLf _
        & "<p class=""warningMsg"">Don't forget to make your picks for the upcoming week!<br/><br/>" & VbCrLf _
        & "<a href=" & POOL_URL & ">Football Pool</a></p>" & VbCrLf _
        & "</td>" & VbCrLf _
        & "</tr>" & VbCrLf _
        & "</table>" & VbCrLf _
        & "</td></tr></table></body></html>"
      sql = "SELECT EmailAddress FROM Users WHERE NotifyOfNewsUpdates = true"
      set rs = DbConn.Execute(sql)
      do while not rs.EOF
       email = Decrypt(rs.Fields("EmailAddress").Value)
       if email <> "" then
        call SendMail(email, subj, body)
       end if
       rs.MoveNext
      loop

     end sub %>

    I think that if you removed the line in blue above it would e-mail everyone regardless of what they have set in there profile. However, I left the code and I check that block for them so that they still have the option of not receiving e-mails. I never heard any complaints last season by doing that so that's what I'm doing this season.

    Doing this method produces a great looking e-mail in Outlook and web-based e-mails (gmail and hotmail) that mirrors your pool. The only thing that doesn't show up is if you have a background image on your pool.

  • 09-10-2009 5:20 AM In reply to

    • drizzt09
    • Top 10 Contributor
    • Joined on 08-22-2009
    • Ontario Canada
    • Posts 399

    Re: email all

     Smokey Jones

    yours is slightly different as it appears you are using SQL vs ACCESS

    there is a bunch of coding in here that is different than the original

  • 09-18-2009 7:39 AM In reply to

    Re: email all

    drizzt09:

     Smokey Jones

    yours is slightly different as it appears you are using SQL vs ACCESS

    there is a bunch of coding in here that is different than the original

    The only difference in my set up is that I have use the Windows SMTP service to send the mail and I have all of the HTML mail formatting in the script. Still using the Access DB.

  • 09-20-2009 8:04 PM In reply to

    • drizzt09
    • Top 10 Contributor
    • Joined on 08-22-2009
    • Ontario Canada
    • Posts 399

    Re: email all

    Smokey Jones:

    I've changed the email.asp to send all messages as HTML by changing the following:

      'Create the email.
      cdoMessage.From     = "Football Pool" & " <" & ADMIN_EMAIL & ">"
      cdoMessage.To       = toAddr
      cdoMessage.Subject  = subjectText
      cdoMessage.HTMLBody = bodyText

    And then I added the HTML formatting to the editNews.asp file:

    <% '**************************************************************************
     '* Local functions and subroutines.                                       *
     '**************************************************************************

     '--------------------------------------------------------------------------
     ' Sends an email notification to any users who have elected to receive
     ' them.
     '--------------------------------------------------------------------------
     sub SendNotifications()

      dim subj, body
      dim sql, rs
      dim email

      subj = PAGE_TITLE & " - News Update Notification"
      body = "<html><head><link rel=""stylesheet"" type=""text/css"" href=""http://www.YOURHOST.com/YOURPOOL/styles/common.css"" /></head>" & VbCrLf _
        & "<body>" & VbCrLf _
        & "<table id=""wrapper"" align=""center""><tr><td>" & VbCrLf _
        & "<table class=""main newsletter"" cellpadding=""0"" cellspacing=""0"">" & VbCrLf _
        & "<tr class=""header bottomEdge"">" & VbCrLf _
        & "<th align=""left"">Football Pool News Update</th>" & VbCrLf _
        & "</tr>" & VbCrLf _
        & "<tr>" & VbCrLf _
        & "<td class=""freeForm"">" & VbCrLf _
        & news & VbCrLf _
        & "<p class=""warningMsg"">Don't forget to make your picks for the upcoming week!<br/><br/>" & VbCrLf _
        & "<a href=" & POOL_URL & ">Football Pool</a></p>" & VbCrLf _
        & "</td>" & VbCrLf _
        & "</tr>" & VbCrLf _
        & "</table>" & VbCrLf _
        & "</td></tr></table></body></html>"

      sql = "SELECT EmailAddress FROM Users WHERE NotifyOfNewsUpdates = true"
      set rs = DbConn.Execute(sql)
      do while not rs.EOF
       email = Decrypt(rs.Fields("EmailAddress").Value)
       if email <> "" then
        call SendMail(email, subj, body)
       end if
       rs.MoveNext
      loop

     end sub %>

    I think that if you removed the line in blue above it would e-mail everyone regardless of what they have set in there profile. However, I left the code and I check that block for them so that they still have the option of not receiving e-mails. I never heard any complaints last season by doing that so that's what I'm doing this season.

    Doing this method produces a great looking e-mail in Outlook and web-based e-mails (gmail and hotmail) that mirrors your pool. The only thing that doesn't show up is if you have a background image on your pool.

     

    the email.asp I already had. The editNews.asp, I dont see anything HTML related that is changed. the green area I have. the red part is completely different in mine. I have:


            list = GetNotificationList("NotifyOfNewsUpdates")
            for each email in list
                call SendMail(email, subj, body)
            next

        end sub %>

  • 09-20-2009 9:36 PM In reply to

    Re: email all

     Did you add this to the SendMail function in email.asp?

      cdoMessage.HTMLBody = bodyText

  • 09-21-2009 2:00 AM In reply to

    • drizzt09
    • Top 10 Contributor
    • Joined on 08-22-2009
    • Ontario Canada
    • Posts 399

    Re: email all

     ya I already had that part from adding Randy's forgot password coding. His required HTML email.

    its the editNews.asp coding that Im confused about.

  • 09-21-2009 7:31 AM In reply to

    Re: email all

     You mean the different red sections in your post? They are doing pretty much the same thing. Smokey's code pulls the email addresses straight from the database which is exactly what the GetNotificationsList function does. Either method should give the same results.

  • 09-21-2009 3:07 PM In reply to

    • drizzt09
    • Top 10 Contributor
    • Joined on 08-22-2009
    • Ontario Canada
    • Posts 399

    Re: email all

     Mike, i sent you an email with a coding script. not sure if you got it. Let me know what you think.

  • 09-21-2009 6:38 PM In reply to

    Re: email all

     Taking from everyone else's code, here's a full script. Note that you'd have to modify the SendHtmlEmail function to work with whatever email component your host has (just like the existing SendMail function).

    <%@ LANGUAGE="VBScript" %>
    <!-- #include file="includes/config.asp" --><!-- #include file="includes/common.asp" --><% PageSubTitle = "Email All Users" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <%    'Limit access to the Administrator.
        call CheckAccess(true) %>
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
        <title><% = PAGE_TITLE & ": " & PageSubTitle %></title>
        <link rel="shortcut icon" href="favicon.ico" />
        <link rel="stylesheet" type="text/css" href="styles/common.css" />
        <link rel="stylesheet" type="text/css" href="styles/print.css" media="print" />
        <script type="text/javascript" src="scripts/scriptLib.js"></script>
        <script type="text/javascript" src="scripts/common.js"></script>
        <script type="text/javascript" src="scripts/tiny_mce/tiny_mce.js"></script>
        <script type="text/javascript">//<![CDATA[
        //=========================================================================
        // Create the TinyMCE control to be used for editing the email.
        //=========================================================================
        tinyMCE.init({
            content_css : "styles/common.css",
            editor_selector : "mceEditor",
            font_size_style_values : "xx-small,x-small,small,medium,large,x-large,xx-large",
            mode : "textareas",
            plugins : "advimage,advlink,emotions,fullscreen,iespell,inlinepopups,layer,media,preview,safari,searchreplace,style,table,xhtmlxtras",
            theme : "advanced",
            theme_advanced_buttons1 : "formatselect,fontselect,fontsizeselect,|,forecolor,backcolor,|,bold,italic,underline,strikethrough",
            theme_advanced_buttons2 : "justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,outdent,indent,blockquote,|,link,unlink,anchor,image,hr,|,charmap,emotions,media",
            theme_advanced_buttons3 : "insertlayer,moveforward,movebackward,absolute,|,tablecontrols,|,visualaid",
            theme_advanced_buttons4 : "styleprops,|,cite,abbr,acronym,del,ins,attribs,|,search,replace,|,undo,redo,|,removeformat,cleanup,code,iespell,|,fullscreen,preview,|,help",
            theme_advanced_font_sizes : "xx-small,x-small,small,medium,large,x-large,xx-large",
            theme_advanced_toolbar_location : "bottom",
            theme_advanced_toolbar_align : "center",
            theme_advanced_path : false,
            theme_advanced_resizing : false
        });
        //]]></script>
    </head>
    <body>
    <!-- #include file="includes/header.asp" -->
    <!-- #include file="includes/siteMenu.asp" -->
        <div id="contentSection">
    <!-- #include file="includes/email.asp" -->
    <!-- #include file="includes/encryption.asp" -->
    <!-- #include file="includes/form.asp" -->
        <table id="mainWrapper" border="0" cellpadding="0" cellspacing="0"><tr><td>
    <%    'Open the database.
        call OpenDB()

        'If an send was requested, process it.
        dim sql, rs
        dim subj, msg, email
        dim str, errorMsg
        if Request.Form("submit") = "Send" then

            subj = Request.Form("subject")
            msg = Request.Form("body")
            sql = "SELECT EmailAddress FROM Users"
            set rs = DbConn.Execute(sql)
            do while not rs.EOF
                email = Decrypt(rs.Fields("EmailAddress").Value)
                if email <> "" then
                    errorMsg = SendHtmlEmail(email, subj, msg)
                    if errorMsg <> "" then
                        call DisplayErrorMessage("Email send failed: " & errorMsg)
                        exit do
                    end if
                end if
                   rs.MoveNext
            loop
            if errorMsg = "" then
                call DisplaySuccessMessage("Emails sent.")
            end if
        end if

        'Display the form.
        dim subjectText, bodyText
        if Request.ServerVariables("Content_Length") > 0 and not IsCancelRequest() then
            subjectText = Request.Form("subject")
            bodyText    = Request.Form("body")
        end if %>
        <form action="<% = Request.ServerVariables("SCRIPT_NAME") %>" method="post">
            <table class="main fixed" border="0" cellpadding="0" cellspacing="0">
                <tr class="header bottomEdge">
                    <th align="left">Send Email to All Users</th>
                </tr>
                <tr>
                    <td class="freeForm">
                        <p><strong>Subject:</strong> <input type="text" name="subject" value="<% = subjectText %>" size="50" /></p>
                        <table class="htmlEditorArea" border="0" cellpadding="0" cellspacing="0"><tr><td style="padding: 0px;">
                            <div style="margin: 0px;">
                                <textarea name="body" class="mceEditor" rows="30" cols="80" style="width: 39em;"><% = bodyText %></textarea>
                            </div>
                        </td></tr></table>
                    </td>
                </tr>
            </table>
            <p><input type="submit" name="submit" value="Send" class="button" />&nbsp;<input type="submit" name="submit" value="Cancel" class="button" /></p>
        </form>
        </td></tr></table>
        </div>
    <!-- #include file="includes/footer.asp" -->
    </body>
    </html>
    <%    '**************************************************************************
        '* Local functions and subroutines.                                       *
        '**************************************************************************

        '--------------------------------------------------------------------------
        ' Sends an email in HTML format and returns an empty string if successful.
        ' Otherwise, it returns the error message.
        '--------------------------------------------------------------------------
        function SendHtmlEmail(toAddr, subjectText, htmlBody)

            dim mailer
            dim cdoMessage, cdoConfig

            'Assume all will go well.
            SendHtmlEmail = ""

            'Configure the message.
            set cdoMessage = Server.CreateObject("CDO.Message")
            set cdoConfig = Server.CreateObject("CDO.Configuration")
            cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing")  = 2
            cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.example.net"
            cdoConfig.Fields.Update
            set cdoMessage.Configuration = cdoConfig

            'Create the email.
            cdoMessage.From     = ADMIN_USERNAME & " <" & ADMIN_EMAIL & ">"
            cdoMessage.To       = toAddr
            cdoMessage.Subject  = subjectText
            cdoMessage.HTMLBody = htmlBody

            'Send it.
            on error resume next
            cdoMessage.Send

            'If an error occurred, return the error description.
            if Err.Number <> 0 then
                SendHtmlEmail = Err.Description
            end if

            'Clean up.
            set cdoMessage = Nothing
            set cdoConfig  = Nothing

        end function %>
     

    Filed under: ,
  • 09-21-2009 8:52 PM In reply to

    • drizzt09
    • Top 10 Contributor
    • Joined on 08-22-2009
    • Ontario Canada
    • Posts 399

    Re: email all

     this replaces the existing editNews.asp completely?

    thanks

  • 09-21-2009 9:02 PM In reply to

    Re: email all

     This would be a separate file, it doesn't update the home page it just sends an email to everyone.

  • 09-22-2009 3:14 PM In reply to

    • drizzt09
    • Top 10 Contributor
    • Joined on 08-22-2009
    • Ontario Canada
    • Posts 399

    Re: email all

     ok so it would be a separate file... emailAll.asp?

    now how does it get used

    when you use edit news, and post news to the homescreen, does it automatically use the file to send the same info by email?

    Im not getting how it gets used or how it works.

     

    thanks and sorry

Page 1 of 2 (23 items) 1 2 Next >
Powered by Community Server (Non-Commercial Edition), by Telligent Systems