码迷,mamicode.com
首页 > 其他好文 > 详细

C#自动发送邮件

时间:2014-07-10 11:45:31      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   cti   for   

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邮箱,并且没有被防护软件拦截");

                }
            }
        }

    }

}

 

C#自动发送邮件,布布扣,bubuko.com

C#自动发送邮件

标签:style   blog   color   os   cti   for   

原文地址:http://www.cnblogs.com/liuhao2050/p/3812078.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!