Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...How to send bulk email to specific role in codeHow to send bulk email to specific role in code
Previous
 
Next
New Post
11/8/2007 9:53 AM
 

I am creating a Classified Ads module for my intranet site.  I would like to be able to send bulk emails to users with a specific roles, the same as the Newsletter modules does there admin menu. 

How can I via code send bulk emails to specific roles is the question?

thanks,

Dean

 

 
New Post
11/8/2007 4:36 PM
 

Hi Dean,

I don't believe there is a function to do that.  Here is the code I use:

        public void SendMailToRoles(string roles, string from, string subject, string body)
        {
            Hashtable ht = new Hashtable();
            UserController uc = new UserController();
            RoleController rc = new RoleController();
            string[] roleSplit = roles.Split(';');
            foreach (string role in roleSplit)
            {
                ArrayList ar = rc.GetUsersInRole(PortalId, role);
                // GetUsersInRole does not return email in early versions of DNN
                foreach (UserRoleInfo uri in ar)
                {
                    UserInfo ui2 = uc.GetUser(PortalId, uri.UserID);
                    ht[ui2.Email] = 1;
                }
            }

            foreach (string key in ht.Keys)
            {
                Globals.SendNotification(PortalSettings.Email, key, "", subject, body);
            }
        }

Good Luck!
Mike

 
New Post
11/8/2007 4:44 PM
 

Here is how the Core does it (DNN v4.03.05):

Private Sub cmdSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSend.Click
    Try
        If txtSubject.Text <> "" And teMessage.Text <> "" Then
            Dim objRecipients As New ArrayList
            Dim objRoles As New RoleController
            Dim objRole As ListItem
            Dim objListItem As ListItem
            Dim objUser As UserInfo
            ' load all user emails based on roles selected
            For Each objRole In chkRoles.Items
                If objRole.Selected Then
                    For Each objUser In objRoles.GetUsersByRoleName(PortalId, objRole.Value)
                        If objUser.Membership.Approved Then
                            objListItem = New ListItem(objUser.Email, objUser.DisplayName)
                            If Not objRecipients.Contains(objListItem) Then
                                objRecipients.Add(objListItem)
                            End If
                        End If
                    Next
                End If
            Next
            ' load emails specified in email distribution list
            If txtEmail.Text <> "" Then
                Dim arrEmail As Array = Split(txtEmail.Text, ";")
                Dim strEmail As String
                For Each strEmail In arrEmail
                    objListItem = New ListItem(strEmail, strEmail)
                    If Not objRecipients.Contains(objListItem) Then
                        objRecipients.Add(objListItem)
                    End If
                Next
            End If
            ' create object
            Dim objSendBulkEMail As New Services.Mail.SendBulkEmail(objRecipients, cboPriority.SelectedItem.Value, teMessage.Mode, PortalSettings.PortalAlias.HTTPAlias)
            objSendBulkEMail.Subject = txtSubject.Text
            objSendBulkEMail.Body &= teMessage.Text
            If ctlAttachment.Url.StartsWith("FileID=") Then
                Dim fileId As Integer = Integer.Parse(ctlAttachment.Url.Substring(7))
                Dim objFileController As New FileController
                Dim objFileInfo As FileInfo = objFileController.GetFileById(fileId, PortalId)
                objSendBulkEMail.Attachment = PortalSettings.HomeDirectoryMapPath & objFileInfo.Folder & objFileInfo.FileName
            End If
            objSendBulkEMail.SendMethod = cboSendMethod.SelectedItem.Value
            objSendBulkEMail.SMTPServer = Convert.ToString(PortalSettings.HostSettings("SMTPServer"))
            objSendBulkEMail.SMTPAuthentication = Convert.ToString(PortalSettings.HostSettings("SMTPAuthentication"))
            objSendBulkEMail.SMTPUsername = Convert.ToString(PortalSettings.HostSettings("SMTPUsername"))
            objSendBulkEMail.SMTPPassword = Convert.ToString(PortalSettings.HostSettings("SMTPPassword"))
            objSendBulkEMail.Administrator = txtFrom.Text
            objSendBulkEMail.Heading = Services.Localization.Localization.GetString("Heading", Me.LocalResourceFile)
            ' send mail
            If optSendAction.SelectedItem.Value = "S" Then
                objSendBulkEMail.Send()
            Else    ' ansynchronous uses threading
                Dim objThread As New Thread(AddressOf objSendBulkEMail.Send)
                objThread.Start()
            End If
            ' completed
            UI.Skins.Skin.AddModuleMessage(Me, Services.Localization.Localization.GetString("MessageSent", Me.LocalResourceFile), DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.GreenSuccess)
        Else
            ' no subject or message
            UI.Skins.Skin.AddModuleMessage(Me, Services.Localization.Localization.GetString("MessageValidation", Me.LocalResourceFile), DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.YellowWarning)
        End If
    Catch exc As Exception    'Module failed to load
        ProcessModuleLoadException(Me, exc)
    End Try
End Sub

Will Strohl

Upendo Ventures Upendo Ventures
DNN experts since 2003
Official provider of the Hotcakes Commerce Cloud and SLA support
 
New Post
11/8/2007 8:56 PM
 

please notice, that the sendBulkmail class has been deprecated in DNN 4.6.0 and replaced by SendTokenizedBulkMail. I am still working on improvements however, i.e. this interface might change again for DNN 5.0


Cheers from Germany,
Sebastian Leupold

dnnWerk - The DotNetNuke Experts   German Spoken DotNetNuke User Group

Speed up your DNN Websites with TurboDNN
 
New Post
11/9/2007 12:48 PM
 

I think DNN Village has a bulk email module that can do this.  Might check dnnvillage.com.

Jeff

 
Previous
 
Next
HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...How to send bulk email to specific role in codeHow to send bulk email to specific role in code


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out