1

私はメールがあるテキストボックス(textBox2)を持っています: thisemail@gmail.com,hello@yahoo.it,YesOrNo@gmail.com,etc..

メールを送信する機能があります:

private void button1_Click(object sender, EventArgs e)
{
    var mail = new MailMessage();
    var smtpServer = new SmtpClient(textBox5.Text);
    mail.From = new MailAddress(textBox1.Text);
    mail.To.Add(textBox2.Text);
    mail.Subject = textBox6.Text;
    mail.Body = textBox7.Text;
    mail.IsBodyHtml = checkBox1.Checked;
    mail.Attachments.Add(new Attachment(textBox9.Text));
    var x = int.Parse(textBox8.Text);
    smtpServer.Port = x;
    smtpServer.Credentials = new System.Net.NetworkCredential(textBox3.Text, textBox4.Text);
    smtpServer.EnableSsl = checkBox2.Checked;
    smtpServer.Send(mail);
}

各メールに別々にメールを送ってほしい。つまり、私が を押して一度button1に彼に電子メールを受け取り、あなたが終わるまで電子メールを送信するときです。どのようにできるのか?

4

2 に答える 2

1

すべての受信者に他のアドレスを見せたくない場合は、代わりにブラインド カーボン コピーを使用できます。

mail.Bcc.Add(textBox2.Text);

本当に同じメールを複数回送信したい場合は、カンマでアドレスを分割し、別のメソッドで既に持っているコードに渡すことができます.

private void button1_Click(object sender, EventArgs e)
{
    foreach(var address in textBox2.Text.Split(","))
        SendMessage(address);
}

private void SendMessage(string address)
{
    var mail = new MailMessage();
    var smtpServer = new SmtpClient(textBox5.Text);
    mail.From = new MailAddress(textBox1.Text);
    mail.To.Add(address);
    mail.Subject = textBox6.Text;
    mail.Body = textBox7.Text;
    mail.IsBodyHtml = checkBox1.Checked;
    mail.Attachments.Add(new Attachment(textBox9.Text));
    var x = int.Parse(textBox8.Text);
    smtpServer.Port = x;
    smtpServer.Credentials = new System.Net.NetworkCredential(textBox3.Text, textBox4.Text);
    smtpServer.EnableSsl = checkBox2.Checked;
    smtpServer.Send(mail);
}
于 2017-01-05T20:11:25.937 に答える