mauricerichard
asked on
ASP.NET - Email - Sending to Distribution Lists
Hello Experts,
I have webforms that send emails to specific email addresses, and this is working fine. But I need to modify these webforms to send emails to distribution lists instead.
A work-around isn't really an option here, as the distribution lists aren't managed by me and will be changing constantly. How can I get this to work?
Thanks,
Moe
I have webforms that send emails to specific email addresses, and this is working fine. But I need to modify these webforms to send emails to distribution lists instead.
A work-around isn't really an option here, as the distribution lists aren't managed by me and will be changing constantly. How can I get this to work?
Thanks,
Moe
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If revealing all email addreses to everyone is an issue as with say sending out a public newletter and you want to personalise the messages, you can perhaps look at http://www.codeproject.com/Articles/15517/Ready-to-use-Mass-Emailing-Functionality-with-C-NE, http://www.aspnetemail.com/rapidmailer/
ASKER
Thanks to everyone that posted, it was quite helpful to me!
ASKER
Here's the function I ended up implementing, in case it can help others. Pass it a distribution list name and it'll return the email addresses as a string, seperated by semicolons.
You should only need to update the LDAP info. My info looked like:
Public Function ReturnDistributionListEmails_as_String(ByVal strDistList As String) As String
Try
Dim objSearch As DirectorySearcher
Dim objEntry As DirectoryEntry
Dim strEmailAddresses As String = ""
objEntry = New DirectoryEntry("LDAP Info")
objSearch = New DirectorySearcher(objEntry)
objSearch.Filter = "CN=" & strDistList
Dim i As Integer = objSearch.Filter.Length
For Each AdObj As SearchResult In objSearch.FindAll()
For Each objName As [String] In AdObj.GetDirectoryEntry().Properties("member")
Dim selIndex As Integer = objName.IndexOf("CN=") + 3
Dim selEnd As Integer = objName.IndexOf(",OU") - 3
Dim dsSearch As New DirectorySearcher(objEntry)
dsSearch.Filter = "CN=" & objName.Substring(selIndex, selEnd).Replace("\", "")
For Each rs As SearchResult In dsSearch.FindAll()
Dim strCurrentEmail As String = Convert.ToString(rs.GetDirectoryEntry().Properties("mail").Value)
If Not strCurrentEmail.Trim = "" Then
strEmailAddresses += strCurrentEmail & ";"
End If
Next
Next
Next
Return (strEmailAddresses.Trim)
Catch ex As Exception
Return ("--Error: " + ex.Message)
End Try
End Function
You should only need to update the LDAP info. My info looked like:
objEntry = New DirectoryEntry("LDAP://mydomain.com/DC=mydomain,DC=com", "user", "pass")