How to send email to multiple address using System.Net.Mail

后端 未结 9 2092
我在风中等你
我在风中等你 2020-11-28 09:03

I have smtp email functionality. it works for single address but has problem in multiple address.

i am passing multiple addresses using following line of code.

9条回答
  •  失恋的感觉
    2020-11-28 09:36

    I'm used "for" operator.

    try
    {
        string s = textBox2.Text;
        string[] f = s.Split(',');
    
        for (int i = 0; i < f.Length; i++)
        {
            MailMessage message = new MailMessage(); // Create instance of message
            message.To.Add(f[i]); // Add receiver
            message.From = new System.Net.Mail.MailAddress(c);// Set sender .In this case the same as the username
            message.Subject = label3.Text; // Set subject
            message.Body = richTextBox1.Text; // Set body of message
            client.Send(message); // Send the message
            message = null; // Clean up
        }
    
    }
    
    catch (Exception ex)
    {
    
        MessageBox.Show(ex.Message);
    }
    

提交回复
热议问题