Unable to send an email to multiple addresses/recipients using C#

前端 未结 6 966
陌清茗
陌清茗 2020-12-01 11:09

I am using the below code, and it only sends one email - I have to send the email to multiple addresses.

For getting more than one email I use:

strin         


        
6条回答
  •  感动是毒
    2020-12-01 11:25

    The problem is that you are supplying a list of addresses separated by semi-colons to the MailMessage constructor when it only takes a string representing a single address:

    A String that contains the address of the recipient of the e-mail message.

    or possibly a list separated by commas (see below).

    Source

    To specify multiple addresses you need to use the To property which is a MailAddressCollection, though the examples on these pages don't show it very clearly:

    message.To.Add("one@example.com, two@example.com"));
    

    The e-mail addresses to add to the MailAddressCollection. Multiple e-mail addresses must be separated with a comma character (",").

    MSDN page

    so creating the MailMessage with a comma separated list should work.

提交回复
热议问题