我创建了一个使用C#发送电子邮件的简单程序。现在我想修改它以一次发送一封电子邮件。
这是我现在的代码,但它无效。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;
using System.Net.Configuration;
using System.Net.NetworkInformation;
using System.Web;
using System.Threading.Tasks;
namespace MailSender
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//Mail properties
private void button1_Click(object sender, EventArgs e)
{
string[] array = { "mail1@mail.com", "mail2@mail.com" };
foreach (string value in array)
{
SmtpClient client = new SmtpClient(comboBox1.Text, 25);
client.Credentials = new NetworkCredential(textBox1.Text, textBox2.Text);
MailMessage msg = new MailMessage();
msg.From = new MailAddress(textBox1.Text);
msg.To.Add(new MailAddress(value));
//msg.To.Add(new MailAddress(textBox3.Text));
msg.Subject = textBox4.Text;
msg.Priority = MailPriority.Normal;
msg.IsBodyHtml = false;
if (checkBox2.Checked)
{
msg.IsBodyHtml = true;
}
msg.Body = richTextBox1.Text;
if (checkBox1.Checked)
{
client.Send(textBox1.Text, textBox1.Text, textBox4.Text, richTextBox1.Text);
}
//Send mail
try
{
client.Send(msg);
progressBar1.Increment(100);
}
catch (SmtpException)
{
MessageBox.Show("Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
}
任何人都可以帮我解决这个问题吗?谢谢:))