发送邮件
[ 2014-8-28 11:14:00 | By: sunlunhao915 ]
 
  /// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="email"></param>
        /// <param name="name"></param>
        /// <param name="activationCode"></param>
        /// <returns></returns>
        public static bool SendMail(string email, string name, string activationCode)
        {

            MailAddress from = new MailAddress("test@test.com ", "测试账号");

            //收件人地址

            MailAddress to = new MailAddress(email, "hello");

            MailMessage message = new MailMessage(from, to);


            message.Subject = "帐号激活邮件"; // 设置邮件的标题

            message.Body = @"http://192.168.0.144:10086/" + "/Activation.ashx/?username=" + name + "&" + "activationCode=" + activationCode;

            message.BodyEncoding = System.Text.Encoding.Default;

            MailAddress other = new MailAddress("otherPerson@163.com");

            //创建一个SmtpClient 类的新实例,并初始化实例的SMTP 事务的服务器

            SmtpClient client = new SmtpClient("192.168.0.250");

            client.DeliveryMethod = SmtpDeliveryMethod.Network;

            client.UseDefaultCredentials = false;

            client.EnableSsl = false;

            //身份认证
            client.Credentials = new System.Net.NetworkCredential("xxxxx@weipu.com", "xxxxx");
            
            bool ret = true; 
            try
            {

                client.Send(message);

            }

            catch (SmtpException )
            {
                
                ret = false;
            }

            catch (Exception)
            {
                ret = false;
            }

            return ret;

        }
 
 
  • 标签:发送邮件 
  • 发表评论:
     

    时 间 记 忆
    <<  < 2014 - >  >>
    1 2
    3 4 5 6 7 8 9
    10 11 12 13 14 15 16
    17 18 19 20 21 22 23
    24 25 26 27 28 29 30
    31
    最 新 评 论
    最 新 日 志
    最 新 留 言
    搜 索
    用 户 登 录
    友 情 连 接


     
    天涯博客欢迎您!