Question Marketing Emial System

atr232000

Member
Joined
Jan 9, 2010
Messages
17
Programming Experience
Beginner
Hello All

I built as email marketing system a while ago and I have been asked to add a feature that should have been there from the start really.

OK i have a structure that holds a list of IDs, Email address and Departments

when the end user goes and presses the email button the for each statement goes though each Item in the structure (Except the first) and pings off a HTML email.
This is stored in a Form as the user has had to pick the email template from a list.

The code is below but as you can see if a message fails, fro any reason the rest of the list gets missed and exit sub!!!
How can i say

if smtp.message.fails then
'add addess to a report list so that the users has a message to show failed message
and continue with the for each statment rather than exit sub
else
'nothing
end if

[XCODE]
Try
For mdlvariables.EmailCouter = 1 To UBound(emaillist)

If emaillist(EmailCouter).emailAddress.Contains("@") Then


Dim localdecodestring As String = EmailDetailsChange(myDecodedString, localEventName, localEventType, LocalEventLocation, localEventdate, localEventTime)
'Dim localdecodestring As String = myDecodedString.Replace("[*Name*]", StrConv(emaillist(EmailCouter).emailName, VbStrConv.ProperCase))


Dim message As System.Net.Mail.MailMessage
Dim smtp As New System.Net.Mail.SmtpClient("Ourserver",Ourport)

message = New System.Net.Mail.MailMessage(tbFrom.Text, emaillist(EmailCouter).emailAddress, tbSubject.Text, localdecodestring)
message.IsBodyHtml = True
smtp.Send(message)


' add a stamp to say when it was sent
Dim sqlInsert As SqlCommand = sqlconn.CreateCommand
sqlInsert.CommandText = "Insert into EmailTracking ([ContactID],[EmailTemplateID],[SentTime]) values" & _
"('" & emaillist(EmailCouter).ContactID.ToString & "','" & localEmailID & "','" & Format(Now.ToString).ToString & "')"
sqlInsert.ExecuteNonQuery()
End If

Next

MsgBox("Emails Sent")

Catch ex As Exception
MsgBox("Error" & vbNewLine & RN & vbNewLine & StrConv(emaillist(emailcouter).emailName, VbStrConv.ProperCase) & vbNewLine & ex.Message)
End Try
[/XCODE]
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,540
Location
Norway
Programming Experience
10+
Try-Catch each email within the loop, rather than the whole loop.
 
Top Bottom