+1 vote

Hello,

we are using limilabs mail components and now we recognized one problem.

If we send an mail to several adresses (to, cc, or bcc) and one of the adresses is a not existing mail adress, all mails will not be delivered.

E.x.:

We sent to an existing adress existingmail@ourdomain.de and as 2nd adress notexistingmail@ourdomain.de . The Email will be sent, but the mail will not be received by the mailaccount existingmail@ourdomain.de.

How can this problem be solved?

Thanks for an answer!

Regards

TK

by (350 points)

1 Answer

0 votes

First be sure to check the return value of the Smtp.SemdMessage method:

ISendMessageResult result = smtp.SendMessage(mail);
switch (result.Status)
{
    case SendMessageStatus.Success:
        break;
    case SendMessageStatus.PartialSucess:
        break;
    case SendMessageStatus.Failure:
        break;
}

By default, sending message fails if any of the recipient is rejected by the SMTP server, so only 2 statuses may be returned: SendMessageStatus.Success and SendMessageStatus.Failure.

You can set Smtp.Configuration.AllowPartialSending property to modify this behavior, messages will be sent even if the SMTP server rejects some recipients:

IMail mail = Fluent.Mail.Text("Sample email")
    .Subject("subject goes here")
    .From("user@example.com")
    .To("invalid@example.com")
    .To("valid@example.com")
    .Create();

using (Smtp smtp = new Smtp())
{
    smtp.Configuration.AllowPartialSending = true; // <-- ignore rejected recipients

    smtp.Connect("smtp.example.com"); // or ConnectSSL for SSL
    smtp.UseBestLogin("user@example.com", "password");

    ISendMessageResult result = smtp.SendMessage(mail);

    Assert.AreEqual(SendMessageStatus.PartialSucess, result.Status);

    switch (result.Status)
    {
        case SendMessageStatus.Success:
            break;
        case SendMessageStatus.PartialSucess:
            // error handling code goes here.
            break;
        case SendMessageStatus.Failure:
            // error handling code goes here.
            CollectionAssert.AreEqual(
                new[] { "invalid@example.com" }, 
                result.RejectedRecipients);
            break;
    }

    client.Close();
}
by (297k points)
...