Hi,
Mail.dll obtained using nuget package, v.3.0.20073.1408
- An SMTP server is used which rejects addressees outside of our domain.
- Mail message contains the same addressee in To/CC/Bcc (one duplicate is enough, like in To and CC to trigger the issue; I did not experiment with the mix of good and bad mails so far).
- A call to Smtp client's SendMessage(email) fails with System.ArgumentException - An item with the same key has already been added.
Notes:
* No issue if duplicate addressees are accepted by the server
* No issue if addressees are rejected, but are unique
My guess is that Mail.dll is attempting to associate the response with each mail address it attempts to send the mail, indexing by mail address, but since there are duplicates, the Dictionary raises an exception?
Let me know if additional information is needed.
While de-duplicating the list of recipients on our side is possible (but will be noticeable by recipients, since some of the addresses the mail was being addressed to will disappear from CC/BCC since they are in To), it looks like a discrepancy in mail.dll implementation?
Code (mail server name is redacted):
private static void SmtpSend()
{
var server = "*****************";
var serverTimeout = 100;
var from = "b@b.c";
var to = "a@b.c";
var cc = "a@b.c";
var bcc = "a@b.c";
var subject = "Test mail";
var text = "Test mail.";
Limilabs.Mail.Log.Enabled = true;
using (Smtp smtpClient = new Smtp())
{
MailBuilder mailBuilder = new MailBuilder();
mailBuilder.From.Add(new MailBox(from));
mailBuilder.To.Add(new MailBox(to));
mailBuilder.Cc.Add(new MailBox(cc));
mailBuilder.Bcc.Add(new MailBox(bcc));
mailBuilder.Subject = subject;
mailBuilder.Text = text;
smtpClient.Connect(server, 25);
IMail email = mailBuilder.Create();
smtpClient.ReceiveTimeout = smtpClient.SendTimeout = new TimeSpan(0, 0, (int) serverTimeout);
var result = smtpClient.SendMessage(email);
}
}
Exception stack:
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 _______00_.__0(List`1 __, List`1 __0) at Limilabs.Client.SMTP.Smtp.__0__0(SmtpMail __)
at Limilabs.Client.SMTP.Smtp.SendMessage(SmtpMail smtpMail)
at Limilabs.Client.SMTP.Smtp.SendMessage(IMail email)
at ConsoleApplication1.Program.SmtpSend() in D:\MyProjects\MailTest\Program.cs:line 63
at ConsoleApplication1.Program.Main(String[] args) in D:\MyProjects\MailTest\Program.cs:line 22
Log (name/ip of the mail server redacted; the name of SMTP that mail.dll is connecting to is an alias resolved to actual mail server, hence):
Mail.dll Information: 0 : 1 22:36:00 3.0.20073.1408
Mail.dll Information: 0 : 1 22:36:00 Checking if license file is present.
Mail.dll Information: 0 : 1 22:36:00 Connecting to '**smtp-alias**:25', SSL/TLS: False.
Mail.dll Information: 0 : 1 22:36:01 S: 220 **actual-smtp** Microsoft ESMTP MAIL Service ready at Wed, 15 Apr 2020 05:36:01 +1000
Mail.dll Information: 0 : 1 22:36:01 C: EHLO [**ip**redacted**]
Mail.dll Information: 0 : 1 22:36:01 S: 250-**actual** Hello [**ip**redacted**]
Mail.dll Information: 0 : 1 22:36:01 S: 250-SIZE 37748736
Mail.dll Information: 0 : 1 22:36:01 S: 250-PIPELINING
Mail.dll Information: 0 : 1 22:36:01 S: 250-DSN
Mail.dll Information: 0 : 1 22:36:01 S: 250-ENHANCEDSTATUSCODES
Mail.dll Information: 0 : 1 22:36:01 S: 250-STARTTLS
Mail.dll Information: 0 : 1 22:36:01 S: 250-X-ANONYMOUSTLS
Mail.dll Information: 0 : 1 22:36:01 S: 250-AUTH NTLM LOGIN
Mail.dll Information: 0 : 1 22:36:01 S: 250-X-EXPS GSSAPI NTLM
Mail.dll Information: 0 : 1 22:36:01 S: 250-8BITMIME
Mail.dll Information: 0 : 1 22:36:01 S: 250-BINARYMIME
Mail.dll Information: 0 : 1 22:36:01 S: 250-CHUNKING
Mail.dll Information: 0 : 1 22:36:01 S: 250 XRDST
Mail.dll Information: 0 : 1 22:36:51 C: MAIL FROM:<b@b.c>
Mail.dll Information: 0 : 1 22:36:51 C: RCPT TO:<a@b.c>
Mail.dll Information: 0 : 1 22:36:51 C: RCPT TO:<a@b.c>
Mail.dll Information: 0 : 1 22:36:51 C: RCPT TO:<a@b.c>
Mail.dll Information: 0 : 1 22:36:51 C: NOOP
Mail.dll Information: 0 : 1 22:36:51 S: 250 2.1.0 Sender OK
Mail.dll Information: 0 : 1 22:36:56 S: 550 5.7.54 SMTP; Unable to relay recipient in non-accepted domain
Mail.dll Information: 0 : 1 22:37:01 S: 550 5.7.54 SMTP; Unable to relay recipient in non-accepted domain
Mail.dll Information: 0 : 1 22:37:06 S: 550 5.7.54 SMTP; Unable to relay recipient in non-accepted domain