当前位置:编程学习 > C#/ASP.NET >>

asp.net发送邮件的问题

 /// <summary>
      /// 发送邮件
      /// </summary>
      /// <returns>返回成功是否的信息</returns>
      public bool SendEmail(SendContentChild content)
      {
          bool IsSuccess = true;
          String log = null;
       
          DateTime Now = DateTime.Now;
          DateTime FixedTime = Now.AddSeconds(content.FixedTime);
         
          if (FixedTime >Now)
          {
              //时间大于当前系统时间
      

              try
              {
                 
                      MailMessage mail = new MailMessage();
                      mail.Subject = content.SendReason;
                      IList<SmtpServer> smtpList = GetAvailableSmtpServer();
                      SmtpServer smtpServer= smtpList.Last<SmtpServer>();
                      mail.From = new MailAddress(smtpServer.ServerAddress);
                      mail.To.Add(content.SenderWay);
                      /* for (int i = 0; i < strToList.Length; i++)                
                       {
                           mail.To.Add(strToList[i]);                
                       } //可以添加多个收件人
                       * */

                      mail.Body = content.Content+"这是由测试发出来的";
                     // mail.Attachments.Add(new Attachment("C:\\Users\\Public\\Pictures\\Sample Pictures\\灯塔.jpg"));
                      mail.Priority = MailPriority.High;
                      SmtpClient smtp = new SmtpClient();
                      smtp.Host = "smtp.163.com";//设置SMTP服务器地址(用于发送邮件的邮箱的SMTP服务器地址)

                      smtp.EnableSsl = true;
                      smtp.UseDefaultCredentials = false;
                      smtp.Credentials = new System.Net.NetworkCredential(smtpServer.ServerAddress, smtpServer.Password); //通行证
                      smtp.DeliveryMethod = SmtpDeliveryMethod.Network; //递送方法 为 网络
                      smtp.Send(mail);

                 
              }
              catch (Exception ex)
              {
                  IsSuccess = false;
                  log = ex.Message;
                  string errorPath = "E:\\" + "error.log";
                  if (!File.Exists(errorPath))
                  {
                      FileStream create = File.Create(errorPath);
                      create.Close();
                  }
                  FileStream fs = new FileStream(errorPath, FileMode.Append, FileAccess.Write);
                  StreamWriter sw = new StreamWriter(fs);
                  sw.WriteLine("Exception: " + ex.Message + " --" + DateTime.Now.ToString());
                  sw.Flush();
                  sw.Close();
                  fs.Close();
              }
          }



          return IsSuccess;

      }
  会发生“会发生“根据验证过程,远程证书无效。”的异常,怎么解决! asp.net 发送邮件 --------------------编程问答-------------------- 用jmail组件收发邮件多好,也方便

http://clockzxj.blog.163.com/blog/static/18950624200971145415678/ --------------------编程问答-------------------- 我要群发定时还有附件,jmail有许多问题 --------------------编程问答-------------------- 我也在纠结发邮件的问题,要实用性大不容易。。。。 --------------------编程问答-------------------- refer : http://blog.csdn.net/chinacsharper/article/details/9750303
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,