Link to home
Start Free TrialLog in
Avatar of GordonPrince
GordonPrinceFlag for United States of America

asked on

troubleshooting sending email via SMTP sometimes duplicates

I'm using VB 2008 to send email messages as shown below with an Exchange 2003 Server. About one message in 10 gets sent multiple times. This has been going on for over a month now. How can I fix this problem?

The original program was written in VB6 using CDO to send the messages. It worked for 5+ years, then started having the trouble about two months ago. I've just finished upgrading it to VB2008 with the techniques shown in the code example window, sent 20 emails this morning and three of them were sent twice.

I've tried resending the messages that duplicated themselves and they usually don't duplicate themselves. Sending the same message 10 different times only results in a duplication 0-2 times. I can't find a pattern. One message last week had 6 recipients on it and they each got 15 copies of the message. But then over the next few days 40-50 messages were sent with no duplicates. Now I've got some duplicates again this morning.

Any ideas how to troubleshoot this problem?
Dim Email As MailMessage, SMTP As New SmtpClient
' first, set the SMTP properties
for each item in the recordset
Email = new MailMessage
with Email
  .From = "me@domain.com"
  .To = .ToAdd(New MailAddress("recip@domain.com"))
  .Subject = strX
  .Body = strY
end with
SMTP.Send(Email)
Email = nothing
next item in recordset
SMTP = nothing

Open in new window

SOLUTION
Avatar of wsewasim
wsewasim

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Rahul Agarwal
Rahul Agarwal
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GordonPrince

ASKER

I don't think there's anything in the code. During the development of the VB 2008 version I sent about 200 messages through a different SMTP server -- no duplicates. So how would I troubleshoot the problem of two different code methods for sending email cause duplications in the production server?
I'm assuming there's no reason I couldn't just use another SMTP server that is external to the network to send these emails, right? It is sub-optimal to send all the emails outside the office to an external SMTP server that will then send the messages back into the office to the individual recipients. But it would work, right? And that would be a way to prove that the problem is in the internal exchange server that's doing the SMTP work, right? Am Ithinking about this correctly?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The SMTP diagnostics uncovered some red (trouble) areas. I'm going to try getting those fixed today or tomorrow, then see how things behave. Thanks.
The network admin added MX and A records and now there are no red action items in the SMTP diagnostics. But out of 13 items programmatically sent via SMTP this morning, 3 of them show up duplicated. (There's a BCC on everything that gets sent, so it's easy to spot the duplicates).

The other logging tools seem to be ways to find messages that are stuck in the queue and aren't getting delivered. I'm sure sure how to read the results to figure out what's causing messages to be sent multiple times (one of them 2 weeks ago was sent 15 times).

Any other ideas or more specific details greatly appreciated.
Hi, I suggest you contact a moderator and ask them to make the following changes to the question:

Change primary zone to Microsoft Exchange Server;
Add to "SMTP" zone.

I think this will help channel the question to the most appropriate experts.
agarw -- what credentials would I use with smtp.gmail.com?
agarw -- I mean, what's the format of the credentials. I have a gmail account, I assume I would use that. I just can't get the code to set my credentials in a way that allows a test message to be sent.
After quite a bit of testing, I may have uncovered the problem. I was able to create a database item that consistently resulted in duplicate emails being sent. One of the recipients was an email address for a group. After changing the members of the group and having the duplicates come and go (but be consistent over several runs when the members of the group were the same), I looked at the group in Active Directory. It was set as a Security type group, not a Distribution type group. When I changed it to be a Distribution type group, the duplicates stopped, regardless of who the members of the group were. This morning I've had a large production run of items and no duplicates. So maybe that's what it was. I wouldn't have thought this should cause the problem, but maybe there was some corruption in the Security group and changing it to Distribution group rebuilt the group as the new type, or something like that. But for now, it appears this may be it. Although this is not definitive, as the problem seemed intermittent, until I was able to find a test item that failed every time.
Glad you appear to have it sorted.
Turns out the problem I found is not the only problem. I've had other duplications in some of the emails since then. But with those when I tried resending the items, they didn't duplicate. I've learned from the network administrator that there are other emails that are getting duplicated, in addition to the ones I'm sending. So there's something wrong with the email system. Thanks to all for the ideas on this.