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