Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29748

Sending e-mail to multiple recipients

$
0
0

I want to send e-mail to multiple recipients in C# through Gmail. This is my code, but this code only send email to one address. How should I modify it?

private void button1_Click(object sender, EventArgs e)
{
        if (textBox1.Text == "" || richTextBox1.Text == "")
        {
            MessageBox.Show("Please fill out the boxes!");
            return;
        }

        try
        {
            MailMessage message = new MailMessage();
            SmtpClient smtp = new SmtpClient();

            message.From = new MailAddress("tamogatas.dolgozoadatbazis@gmail.com");
            message.To.Add(new MailAddress(Form1.cimzett));
            message.Subject = textBox1.Text;
            message.Body = richTextBox1.Text + Environment.NewLine +  "This message was sent from " + (Login.loginnev);

            smtp.Port = 587;
            smtp.Host = "smtp.gmail.com";
            smtp.EnableSsl = true;
            smtp.UseDefaultCredentials = false;
            smtp.Credentials = new NetworkCredential("USERNAME@gmail.com", "PASSWORD");
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            smtp.Send(message);
            MessageBox.Show("The mail was sent successfully!");
        }
        catch (Exception ex)
        {
            MessageBox.Show("Error " + ex.Message);
        }
}

Thanks for the answers!


Viewing all articles
Browse latest Browse all 29748

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>