如何在asp.net mvc 5中发送群发邮件 [英] How to send mass email in asp.net mvc 5
本文介绍了如何在asp.net mvc 5中发送群发邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我需要一种方法来发送包含来自asp.net mvc 5的某种信息的群发电子邮件,我知道如何使用SmtpClient类,但是不能用于各种方向,请,需要你的帮助,谢谢...
Hello everyone, I need a way to send mass emails containing some kind of information from asp.net mvc 5, i know how to do this with SmtpClient class, but doesn't work with various directions, please, need your help, thanks...
推荐答案
嗯,这很简单,我唯一需要做的就是制作一个MailAdressCollection,然后插入所有的电子邮件,然后用foreach发送到我的Collection中的每个addressess,下面是我的代码:
Well, that was definetly easy, the only thing that I needed to do is to make a "MailAdressCollection" and then insert all the emails, and then with a foreach send to each one of the addressess in my Collection, below is my code:
static void Main(string[] args)
{
MailAddressCollection collection = new MailAddressCollection();
collection.Add("xxx@xxx.xx");
collection.Add("xxx@xxx.xx");
foreach (var item in collection)
{
var to = item;
var from = new MailAddress("xxx@xxx.xx");
var message = new MailMessage(from, to);
message.Subject = "Contract";
message.Body = @"Hello, you and your team have been classified to go directly to World Finals for good performance in previous competitions and cups, Sincerely, ICPC Team.";
// Use the application or machine configuration to get the
// host, port, and credentials.
var client = new SmtpClient("xxx");
client.Credentials = new NetworkCredential("xxx", "xxxx");
//client.EnableSsl = true;
Console.WriteLine("Sending an e-mail message to {0} at {1} by using the SMTP host={2}.",
to.User, to.Host, client.Host);
try
{
client.Send(message);
}
catch (Exception ex)
{
Console.WriteLine("Exception caught in CreateTestMessage3(): {0}",
ex.Message);
}
}
}
}
这篇关于如何在asp.net mvc 5中发送群发邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文