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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vb.net code is sending more than one email in error

Status
Not open for further replies.

t1hodges

MIS
May 8, 2003
54
hello, plee for help.

im writing code to send and email message to one recipient but it sends two in error. here's my code below.

Imports System
Imports System.Data.SqlClient
Imports System.Data.Odbc
Imports System.Net.Mail
Imports System.Reflection
Imports System.Data.OleDb

Private Sub SendEMail(ByVal x, ByVal y, ByVal z)
'x strEmailSubject
'y strRecipients
'z strEmailBody

Dim a As Microsoft.Office.Interop.Outlook.Application
a = CreateObject("Outlook.Application")
Dim b As Microsoft.Office.Interop.Outlook.NameSpace
b = a.GetNamespace("MAPI")
b.Logon()
Dim c, d As Object
Dim f As Microsoft.Office.Interop.Outlook.MailItem
f = a.CreateItem(d)
f.To = "myemailaddress@mydomain.com"
f.Subject = x
f.Body = z
f.Send()
b.Logoff()
b = Nothing
f = Nothing
c = Nothing
a = Nothing
End Sub
 

How many places in your code do you call Sub SendEMail?
Is it possibile to have the call in a loop that runs twice?


Have fun.

---- Andy
 

You should be able to step thru your code and see why it is running twice. Sometimes just because you think it will go thru this logic just once doesn't mean it will do it.

I would put a break on the line
[tt]Private Sub SendEMail[/tt]

Sometimes, for example, when you populate a combo box, it will take an Index of -1 and combo will run thru SelectedIndexChange once, and then you assign Index to 0 and you run thru SelectedIndexChange again.



Have fun.

---- Andy
 
i found the problem. there was an Outlook email rule that was causing the duplication ><
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top