.Net System.Mail.Message adding multiple “To” addresses

前端 未结 8 1427
悲&欢浪女
悲&欢浪女 2020-12-30 18:56

EDIT: This question is pointless, except as an exercise in red herrings. The issue turned out to be a combination of my idiocy (NO ONE was being emailed as the hos

8条回答
  •  余生分开走
    2020-12-30 19:35

    I wasn't able to replicate your bug:

    var message = new MailMessage();
    
    message.To.Add("user@example.com");
    message.To.Add("user2@example.com");
    
    message.From = new MailAddress("test@example.com");
    message.Subject = "Test";
    message.Body = "Test";
    
    var client = new SmtpClient("localhost", 25);
    client.Send(message);
    

    Dumping the contents of the To: MailAddressCollection:

    MailAddressCollection (2 items)
    DisplayName User Host Address

    user example.com user@example.com
    user2 example.com user2@example.com

    And the resulting e-mail as caught by smtp4dev:

    Received: from mycomputername (mycomputername [127.0.0.1])
         by localhost (Eric Daugherty's C# Email Server)
         3/8/2010 12:50:28 PM
    MIME-Version: 1.0
    From: test@example.com
    To: user@example.com, user2@example.com
    Date: 8 Mar 2010 12:50:28 -0800
    Subject: Test
    Content-Type: text/plain; charset=us-ascii
    Content-Transfer-Encoding: quoted-printable
    
    Test
    

    Are you sure there's not some other issue going on with your code or SMTP server?

提交回复
热议问题