–1 vote

When sending emails in a batch (30 or more) smtp.SendMessage(IMail) throws an exception:

"An item with the same key has already been added"

My code for sending messages:

ISendMessageResult result = smtp.SendMessage(email);

Exception:

System.ArgumentException was caught
  _HResult=-2147024809
  _message=An item with the same key has already been added.
  HResult=-2147024809
  IsTransient=false
  Message=An item with the same key has already been added.
  Source=mscorlib
StackTrace:
    at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
    at System.Collections.Generic.Dictionary 2.Insert(TKey key, TValue value, Boolean add)
    at System.Collections.Generic.Dictionary 2.Add(TKey key, TValue value)
    at    . (List 1  , List 1  )
    at Limilabs.Client.SMTP.Smtp. (SmtpMail  )
    at Limilabs.Client.SMTP.Smtp.SendMessage(SmtpMail smtpMail)
    at Limilabs.Client.SMTP.Smtp.SendMessage(IMail email)
    at MailSender.sendMailMessage(IMail email) in c:\MYTFS\MailSender.cs:line 700
    at MailSender.mail(List 1 userIDs, List`1 mids, String[] externDataString, 
     Boolean& result, Nullable 1& mailings_id, Boolean uploadToSent, String replyTo) 
 in c:\MyTFS\MailSender.cs:line 492

What could be the reason for this?

Is there any kind of timeout associated with communication between an smtp server for sending and the smtp client object?

Any advice is greatfully accepted.

Best Regards /AJ

by
reshown by

1 Answer

0 votes

As said before. This error has been already corrected. Please use the latest version.

If you are still experiencing this issue (which I doubt) please attach the logs.

Most likely your server disconnects after some failure while sending a message (SMTP servers shouldn't do that, but some do). This means that subsequent RSET command issued by Mail.dll fails and throws an exception. If that happens, you can always use Exception.Data["SendMessageResult"] entry to get the actual sending result. Also examining the logs may help you.

Is there any kind of timeout associated with communication between an smtp server for sending and the Smtp client object?

This error has nothing to do with timeouts, why do you insist it is timeout related?

As explained before: timeout values are specified by 2 properties: SendTimout and ReceiveTimout.

by (301k points)
...