Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post

    Sending Newsletter

    On a website I am building I have created a form where the user can enter their email address into an Access DB. I would then like to send a mass email to all the addresses in the DB. However I can't find out how to do this. One way I tried was by binding a checkboxlist (id="mailinglist") then the emails that have been checked are sent an email. However when I tried this by using this code:

    Code:
    oMessage.To = Mailinglist.SelectedItem.Text
    Only the first email on the list was sent the email.

    Can someone please tell me how to get round this?

    Thanks,
    Curt.

  • #2
    Regular Coder Nischumacher's Avatar
    Join Date
    Oct 2005
    Location
    Bombay, India
    Posts
    196
    Thanks
    0
    Thanked 2 Times in 2 Posts
    you cannot use SelectedItem for a checkboxlist...
    you have to loop though each item and ckeck if it is selected...
    - NS 666
    .net DEVILoper

  • #3
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Nischumacher
    you cannot use SelectedItem for a checkboxlist...
    you have to loop though each item and ckeck if it is selected...
    How would I do this?

  • #4
    Regular Coder Nischumacher's Avatar
    Join Date
    Oct 2005
    Location
    Bombay, India
    Posts
    196
    Thanks
    0
    Thanked 2 Times in 2 Posts
    try this
    Code:
    Dim li As ListItem
    For Each li In CheckBoxList1.Items
     If li.Selected = True Then
      ... do something ...
     End If
    Next
    - NS 666
    .net DEVILoper

  • #5
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post
    What would I put where it says: '...do something...'.
    Apparently I can't put my whole button sub-routine in there as it wouldn't work.

  • #6
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    How is your table set up? Do you have a specific table for the mailing list, and you store all the information in there? Or, is it apart of your users table, and you set a email flag on?

    Either way, you should be able to do it with your query.

    Select all of your fields from your table. For each person in the result send them an email.

    Good luck;

  • #7
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post
    I use a table called 'Mailing'. On the homepage (http://www.rallystuff.net/lomax/) there is a form to join the newsletter. This table has three columns. ID, Email, Date.

  • #8
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    So you should be able to send an email to everyone in that table, what is the need for the checkboxes?

    Select all the emails from the table and send them a message.

    Good luck;

  • #9
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Brandoe85
    So you should be able to send an email to everyone in that table, what is the need for the checkboxes?

    Select all the emails from the table and send them a message.

    Good luck;
    I was using checkboxes as a way of selecting the emails as I don't know what to put here otherwise:

    Code:
    oMessage.To = ???
    What would you put where I have '???' in this case then?

    Thanks.

  • #10
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Select them in your query.

    Set up a mail function, have it take an email address as a parameter. Then, when you execute your query, loop through all of your email addresses passing that email address from the table to the function.

    Or am I making no sense?

  • #11
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Brandoe85
    Select them in your query.

    Set up a mail function, have it take an email address as a parameter. Then, when you execute your query, loop through all of your email addresses passing that email address from the table to the function.

    Or am I making no sense?
    You probably are making sense, but I haven't done much coding like this .

    Would you be able to give me an example code if its not too long please?

    Thanks.

  • #12
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Sure, just have to check, are you using VB or C#?

  • #13
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    I'll assume VB

    Sub to get the emails from the table:
    Code:
    Private Sub Email()
    	Dim strConString = "your connection string"
    	Dim strQuery As String = "SELECT EMAIL FROM MAILING"
    	Dim objCon As New OleDbConnection(strConString)
    	Dim objCommand As New OleDbCommand(strQuery, objCon)
    	objCon.Open()
    	Dim reader As OleDbDataReader
    	reader = objCommand.ExecuteReader()
    	While reader.Read()
    	    Me.SendEmail(reader.GetString(0))
    	End While
    	reader.Close()
    	objCon.Close()
    End Sub
    Sub to send the emails:
    Code:
    Private Sub SendEmail(ByVal strEmail As String)
    	' do all of your email stuff here
    	' oMessage.To = strEmail
    End Sub
    Then call Email() wherever.


    Good luck;

  • #14
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post
    Thanks for your help Brandoe85

  • #15
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post
    I have put the two sub routines you mentioned into my script, and believe I have done that ok, but I don't know how to edit the button sub routine to get it to work correctly:

    Code:
        Sub btnsubmit_Click(ByVal sender As Object, ByVal e As EventArgs)
        
            If Page.IsValid Then
                
                Email()
                
                
            End If
        End Sub
    Any ideas where I have gone wrong

    Thanks.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •