0 votes


I sometimes send duplicate emails. After using it for 3 year in my Classic asp application we now use it in .Net.
In Classic asp no problem but in the .Net there is this problem.

The strangest thing is it sends sometimes an duplicate email. In the log of our smtp server I can find the duplicate email with different email id's. Then I changed my code and inserted an unique number in the body of the email. When the dupplicate email is send, the unique number is the same. I'm almost sure Mail.dll is producing the duplicate email.

I can't reproduce it, it is random.

Dim rsa As RSACryptoServiceProvider = New  PemReader()
Using smtp As New Smtp()
        = SslProtocols.Tls12
    Dim builder As New MailBuilder()
    builder.Text = textversie
    builder.Html = html
    builder.Subject = subject
    builder.From.Add(New MailBox("mailing@mydomain.com"))
    builder.[To].Add(New MailBox(emailadres))
    builder.DKIMSign(rsa, "key1", "Mydomain.com")
    Dim email As IMail = builder.Create()
    Dim result As ISendMessageResult = smtp.SendMessage(email)
End Using
by (210 points)

1 Answer

+1 vote

It is not possible for Mail.dll to send duplicate emails, as Mail.dll does not retry its calls.

IMail.MessageId is created and assigned in MailBuilder.Create method.
If the message ids are different, it means that your application is creating those duplicates (calling Create, Send sequence more than once).

Your code sample is not entirely correct:

  1. You ignore a value returned form Smtp.SendMessage call.
  2. Smtp.Close may throw an exception (e.g. on network issues) - I don't see you marking the message as already send in such case. You may want to use Smtp.Close(false).

Please update to the latest version and turn on logging:

by (272k points)