Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sending email based on a checkboxlist using select case

Status
Not open for further replies.

devondago

Programmer
Jan 22, 2003
38
0
0
US
I have a form that contains a checkboxlist. Based on the selection made on that checkbox list and once the user submits the form I have to send an email based on the selected topic. for each topic i have a person that needs to be receiving this email.
<tr>
<td class="NavyBold">Choose a Category:</td>
<td><asp:checkboxlist id="chksubtest" Runat="server" RepeatDirection="Vertical" RepeatColumns="2" AutoPostBack="false">
<asp:ListItem Value="Europe"></asp:ListItem>
<asp:ListItem Value="Australia"></asp:ListItem>
<asp:ListItem Value="North America"></asp:ListItem>
<asp:ListItem Value="Central America"></asp:ListItem>
<asp:ListItem Value="South America"></asp:ListItem>
<asp:ListItem Value="Asia"></asp:ListItem>
</asp:checkboxlist></td>
</tr>

I have decided to use select case. I tested the email and selected a topic but no email is being sent. Can someone take a look at this and let me know if I need to add anything else? or have a better suggestions.

thanks in advance....!
Here is the logic for my code....

Public Sub SendAMessage(ByVal chksubtest As String)
Dim Message As MailMessage = New MailMessage

Message.From = "post@test.net"

Select Case chksubtest
Case "Europe" : Message.To = "test1@test.net"
Message.Subject = "Europe"
Message.Body = "There is a new Europe Form that was submitted. Please click on the following link Try

SmtpMail.SmtpServer = "TESTC01.TEST.com"
SmtpMail.Send(Message)

Catch ehttp As System.Web.HttpException
'Catch error here
End Try

Case "Asia" : Message.To = "test2@test.net"
Message.Subject = "Asia"
Message.Body = "There is a new Asia Form that was submitted. Please click on the following link
Try

SmtpMail.SmtpServer = "TESTC01.TEST.com"
SmtpMail.Send(Message)

Catch ehttp As System.Web.HttpException
'Catch error here
End Try

Case "North America" : Message.To = "test3@test.net"
Message.Subject = "North America"
Message.Body = "There is a new North AmericaForm that was submitted. Please click on the following link
Try

SmtpMail.SmtpServer = "TESTC01.TEST.com"
SmtpMail.Send(Message)

Catch ehttp As System.Web.HttpException
'Catch error here
End Try


Case "Central America" : Message.To = "test4@test.net"
Message.Subject = "Central America"
Message.Body = "There is a new Central America Form that was submitted. Please click on the following link
Try

SmtpMail.SmtpServer = "TESTC01.TEST.com"
SmtpMail.Send(Message)

Catch ehttp As System.Web.HttpException
'Catch error here
End Try

Case "South America" : Message.To = "test5@test.net"
Message.Subject = "South America"
Message.Body = "There is a new South America Form that was submitted. Please click on the following link
Try

SmtpMail.SmtpServer = "TESTC01.TEST.com"
SmtpMail.Send(Message)

Catch ehttp As System.Web.HttpException
'Catch error here
End Try

Case "Australia" : Message.To = "test6@test.net"
Message.Subject = "Australia"
Message.Body = "There is a new Australia Form that was submitted. Please click on the following link
Try

SmtpMail.SmtpServer = "TESTC01.TEST.com"
SmtpMail.Send(Message)

Catch ehttp As System.Web.HttpException
'Catch error here
End Try

Case Else
Message.To = "test7@test.net"
Message.Subject = "New email from forms"
Try

SmtpMail.SmtpServer = "TESTC01.TEST.com"
SmtpMail.Send(Message)

Catch ehttp As System.Web.HttpException
'Catch error here
End Try
End Select


End Sub
 
Don't know why but you've got a hell of a lot of unnecessary code...

Code:
Public Sub SendAMessage(ByVal chksubtest As String)
        Dim Message As MailMessage = New MailMessage

        Message.From = "post@test.net"

        Select Case chksubtest
            Case "Europe" : Message.To = "test1@test.net"
                Message.Subject = "Europe"
                Message.Body = "There is a new Europe Form that was submitted. Please click on the following link [URL unfurl="true"]http://test/admin/testMain.aspx"[/URL]

            Case "Asia" : Message.To = "test2@test.net"
                Message.Subject = "Asia"
                Message.Body = "There is a new Asia Form that was submitted. Please click on the following link [URL unfurl="true"]http://test/admin/testMain.aspx"[/URL]


            Case "North America" : Message.To = "test3@test.net"
                Message.Subject = "North America"
                Message.Body = "There is a new North AmericaForm that was submitted. Please click on the following link [URL unfurl="true"]http://test/admin/testMain.aspx"[/URL]

            Case "Central America" : Message.To = "test4@test.net"
                Message.Subject = "Central America"
                Message.Body = "There is a new Central America Form that was submitted. Please click on the following link [URL unfurl="true"]http://test/admin/testMain.aspx"[/URL]

            Case "South America" : Message.To = "test5@test.net"
                Message.Subject = "South America"
                Message.Body = "There is a new South America Form that was submitted. Please click on the following link [URL unfurl="true"]http://test/admin/testMain.aspx"[/URL]

            Case "Australia" : Message.To = "test6@test.net"
                Message.Subject = "Australia"
                Message.Body = "There is a new Australia Form that was submitted. Please click on the following link [URL unfurl="true"]http://test/admin/testMain.aspx"[/URL]


            Case Else
                Message.To = "test7@test.net"
                Message.Subject = "New email from forms"

        End Select
        
        Try

            SmtpMail.SmtpServer = "TESTC01.TEST.com"
            SmtpMail.Send(Message)
    
        Catch ehttp As System.Web.HttpException
            'Catch error here
        End Try

    End Sub

Removes all the sending duplications.

Craig
 
I have modified the code to your suggestion. But the email is not being send.? anything you see that i need to modified?

thanks in advance....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top