C# 如何用C语言发送多个名称为的电子邮件地址#
如何发送多个名为C#的电子邮件地址?目前我需要从数据库中加载姓名和电子邮件地址并发送C# 如何用C语言发送多个名称为的电子邮件地址#,c#,email,C#,Email,如何发送多个名为C#的电子邮件地址?目前我需要从数据库中加载姓名和电子邮件地址并发送 所以我应该先创建字符串数组来存储姓名和电子邮件地址 那我怎样才能发送电子邮件呢?必须将MailMessages()或MailAddress用于多个邮件地址 我的代码 while (sdrReader.Read()) { ReceiverName = sdrReader["Name"].ToString(); ReceiverEmail = sdrReader["EmailAddres
while (sdrReader.Read())
{
ReceiverName = sdrReader["Name"].ToString();
ReceiverEmail = sdrReader["EmailAddress"].ToString();
}
//邮件添加,在这里我想得到多个电子邮件名称和地址,然后发送它们
mail.To.Add(new MailAddress(ReceiverEmail, ReceiverName));
sSQL = @"SELECT * FROM EmailSystem";
try
{
scConnection.Open();
scCommand = new SqlCommand(sSQL, scConnection);
sdrReader = scCommand.ExecuteReader();
while (sdrReader.Read())
{
ReceiverName = sdrReader["Name"].ToString();
ReceiverEmail = sdrReader["EmailAddress"].ToString();
}
}
try
{
// Instance of Mail Server
MailMessage mail = new MailMessage();
// Instance of SMTP Server
SmtpClient server = new SmtpClient(smtpAddress);
mail.To.Add(new MailAddress(ReceiverEmail, ReceiverName));
}
您可以自动使用Microsoft Outlook以编程方式发送电子邮件。有关更多信息,请参阅 使用Dataset或Datatable代替数据读取器,并对每个读取器的值进行迭代 希望以下链接能为发送大量电子邮件提供更好的指导
这是您为实现目标而可能使用的草图。我不接触数据库连接,我希望您检查是否可以从数据库读取数据。如果你有更多的问题,请不要犹豫
// define the body of your mail
var message = new MailMessage
{
From = new MailAddress("foo@gmail.com", "John Doe"),
Subject = "Please don't spam me",
Body = "I will be very angry if you send me spam."
};
// if you don't use gmail, then you have to specify your own settings!!!
var client = new SmtpClient("smtp.gmail.com", 587)
{
EnableSsl = true,
Credentials = new NetworkCredential("foo@gmail.com", "superPassword")
};
// I skipped the creation of connection and command.
// Don't forget to call Dispose when you finish to work with database.
while (sdrReader.Read())
{
var to = new MailAddress(sdrReader["EmailAddress"].ToString(),
sdrReader["Name"].ToString());
message.To.Add(to);
}
client.Send(message);
我想要的是C:)如果你不懂VB.NET,你可以用任何一个。你能给我一些例子吗?我试图使用ArrayList,但我的代码无法运行。我还在调试。所以你的建议是1。使用Datatable加载数据2。将数据从Datatable放入ArrayList 3。然后将数据从ArrayList发送回电子邮件发送,对吗?在这里,我只是编写伪代码。1.将数据绑定到datatable 2。获取姓名和电子邮件,并将其添加到邮件消息中。每个循环,而不是伪循环,你能为我写一个C#示例吗?因此我有点头疼。将你的mail.To.Add移动到while循环中,你会没事的。你能给我一些例子吗?刚才我试图用while加载它,但是while循环中没有数据。在这种情况下,问题出在sdrReader上。没有足够的代码来诊断您现在发布的内容的问题,代码在那里:)您能帮我吗@请:)