C#自动发送邮件

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;

namespace QQEmail
{
    class Program
    {
        static void Main(string[] args)
        {

            for (int i = 0; i < 50; i++)
            {
                MailMessage mymail = new MailMessage();
                mymail.From = new System.Net.Mail.MailAddress("邮箱@qq.com");
                mymail.To.Add("haoliu2050@163.com");
                mymail.Subject = "C#自动发送邮件测试 From HaoLiu TO 1399449842@qq.com";
                mymail.Body = "不好意思,我在测试程序,刚才把QQ号写错了,Sorry!";
                mymail.IsBodyHtml = true;
                SmtpClient smtpclient = new SmtpClient();
                smtpclient.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtpclient.Host = "smtp.qq.com";
                smtpclient.Credentials = new System.Net.NetworkCredential("邮箱@qq.com", "密码");
                try
                {
                    smtpclient.Send(mymail);
                    Console.WriteLine("发送成功");


                }
                catch (Exception ex)
                {
                    Console.WriteLine("发送邮件失败.请检查是否为qq邮箱,并且没有被防护软件拦截");

                }
            }
        }

    }

}

 

posted on 2014-06-27 15:29  404 NotFound!  阅读(442)  评论(0编辑  收藏  举报

导航