首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C# 邮件群发解决思路

2013-04-21 
C# 邮件群发想写个邮件群发的软件 网上的代码都太老了有问题好长时间没写了 当时用net.mail写过 但一直有

C# 邮件群发
想写个邮件群发的软件 网上的代码都太老了有问题
好长时间没写了 当时用net.mail写过 但一直有问题
哪位高手有现成的打包一个给我呗 
在此谢过了C# 邮件群发解决思路 C# 邮件群发 邮件 软件 源码
[解决办法]


   //实例化SmtpClient
   SmtpClient client = new SmtpClient("smtp.126.com", 25);

   //出站方式设置为NetWork
   client.DeliveryMethod = SmtpDeliveryMethod.Network;
                
   //smtp服务器验证并制定账号密码
    client.Credentials = new NetworkCredential("123@126.com", "123");

   MailMessage message = new MailMessage();
   message.Priority = MailPriority.Normal; //设置优先级

   message.SubjectEncoding = Encoding.GetEncoding("gb2312");//主题编码
   message.BodyEncoding = Encoding.GetEncoding("gb2312"); //正文编码
   message.IsBodyHtml = true;//邮件正文是否支持HTML

   message.From = new MailAddress("123@126.com", "标题", Encoding.GetEncoding("gb2312"));//设置收件方看到的邮件来源为:发送方邮件地址、来源标题、编码

                message.To.Add(_sendTo);//接收方

                message.Subject = _title; //标题
                message.Body = _info;
                client.Send(message);


[解决办法]
我去年写过,但是代码不在本机,在我的手提,可惜俺的手提去了上海。
很简单其实,你把需要群发的email address存放在数据库或者是xml==类型中,只要能读取的到就好。
最后用for循环或者是.net的Theard就ok了。
sing System;
using System.Threading;
public class Example {
    public static void Main() {
        // Queue the task.
        ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc));

        Console.WriteLine("Main thread does some work, then sleeps.");
        // If you comment out the Sleep, the main thread exits before
        // the thread pool task runs.  The thread pool uses background
        // threads, which do not keep the application running.  (This
        // is a simple example of a race condition.)
        Thread.Sleep(1000);

        Console.WriteLine("Main thread exits.");
    }

    // This thread procedure performs the task.
    static void ThreadProc(Object stateInfo) {


        // No state object was passed to QueueUserWorkItem, so 
        // stateInfo is null.
        Console.WriteLine("Hello from the thread pool.");
    }
}
http://technet.microsoft.com/zh-cn/magazine/system.threading.threadpool(VS.90).aspx

热点排行