Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everybody

I have small project but i don't know how to use loop and send email to mailing list, who can help me edit my project

Thanks.
Posted
Comments
vinasharing 10-Oct-10 13:10pm    
http://vinasharing.com/adv/SendMail.zip
Keith Barrow 10-Oct-10 13:10pm    
Please add the portion of your source code that defines the mailing list. There are a few ways to loop and the best will depend on how you have handled it.
Keith Barrow 10-Oct-10 13:12pm    
erm, I'm not opening that, nor will anyone else with any sense.
Please edit your post, as paste the code into your question, don't forget to tag it with <pre> tags
vinasharing 10-Oct-10 13:19pm    
<pre>Private Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim mymailmessage As New MailMessage
mymailmessage.From = New MailAddress(TextBox1.Text)
mymailmessage.To.Add(TextBox3.Text)
mymailmessage.Subject = (TextBox4.Text)
mymailmessage.Body = (TextBox5.Text)
Dim smtpserver As New SmtpClient("smtp.gmail.com")
smtpserver.Port = (587)
smtpserver.Credentials = New System.Net.NetworkCredential(TextBox1.Text, TextBox2.Text)
smtpserver.EnableSsl = True
smtpserver.Send(mymailmessage)
Label7.Text = Val(Label7.Text + 1)
On Error Resume Next
ProgressBar1.PerformStep()
If ProgressBar1.Value >= ProgressBar1.Maximum Then
Timer1.Enabled = False
End If
End Sub

<pre lang="vb">Private Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim mymailmessage As New MailMessage
        mymailmessage.From = New MailAddress(TextBox1.Text)
        mymailmessage.To.Add(TextBox3.Text)
        mymailmessage.Subject = (TextBox4.Text)
        mymailmessage.Body = (TextBox5.Text)
        Dim smtpserver As New SmtpClient("smtp.gmail.com")
        smtpserver.Port = (587)
        smtpserver.Credentials = New System.Net.NetworkCredential(TextBox1.Text, TextBox2.Text)
        smtpserver.EnableSsl = True
        smtpserver.Send(mymailmessage)
        Label7.Text = Val(Label7.Text + 1)
        On Error Resume Next
        ProgressBar1.PerformStep()
        If ProgressBar1.Value >= ProgressBar1.Maximum Then
            Timer1.Enabled = False
        End If
    End Sub

 
Share this answer
 
Hello.
First of all Label7.Text = Val(Label7.Text + 1) this doesn't seem right it should be like Label7.Text = Val(Label7.Text) + 1

Secondly, you've put all of this in a timer event, you have to realize that if this is just a piece of the code that runs and if anywhere within the running code you call for application.doevents your timer will get fired and the sub may have not finished by that time.

As for the mailing list, you could do For Each Next if you have a list of e-mail adresses you want to send to.
In this case it would be like
VB
Private Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim mymailmessage As New MailMessage
        mymailmessage.From = New MailAddress(TextBox1.Text)
           For Each address_book_record as string in Listbox1.items 'example if you use a listbox to store addresses
            mymailmessage.To.Add(address_book_record)
           Next
        mymailmessage.Subject = (TextBox4.Text)
        mymailmessage.Body = (TextBox5.Text)
        Dim smtpserver As New SmtpClient("smtp.gmail.com")
        smtpserver.Port = (587)
        smtpserver.Credentials = New System.Net.NetworkCredential(TextBox1.Text, TextBox2.Text)
        smtpserver.EnableSsl = True
        smtpserver.Send(mymailmessage)
        Label7.Text = Val(Label7.Text) + 1
        On Error Resume Next
        ProgressBar1.PerformStep()
        If ProgressBar1.Value >= ProgressBar1.Maximum Then
            Timer1.Enabled = False
        End If
    End Sub


This would send your mail message to all the addresses in the listbox1.
 
Share this answer
 
Comments
Simon_Whale 11-Oct-10 10:45am    
personally change it too

for each mail_address as string in listbox1.items
Sendmail(mail_address)
next

public sub SendMail(byref MailAddress as string)
.. do send mail task here
end sub

this way you have less chance to get caught by mail filters.. large to and cc address lists are 99.9% seen as spam by mail filters
Holc 11-Oct-10 12:10pm    
indeed

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900