none
asp.net smtp发送邮件问题 RRS feed

  • 问题

  • 大家好,我在页面中用smtp写了一个发邮件的功能,也实现了,碰到一个问题,我的邮件内容中有一个超链接,发送成功后会被过滤为垃圾邮件或者直接将网址过滤掉,有人知道原因么?以下是代码片段

      public MailCfg getMailCfg(TicketEntity objTicketEntity, SysCustomerEntity objSysCustomerEntity)
            {
                MailCfg mailCfg = new MailCfg();
                mailCfg.Host = System.Configuration.ConfigurationSettings.AppSettings["SmtpServer"].ToString();
                mailCfg.Username = System.Configuration.ConfigurationSettings.AppSettings["SmtpUser"].ToString();
                mailCfg.Userpwd = System.Configuration.ConfigurationSettings.AppSettings["SmtpPass"].ToString();
                mailCfg.Fromuser = System.Configuration.ConfigurationSettings.AppSettings["FromUser"].ToString();
                mailCfg.Fromdisplay = System.Configuration.ConfigurationSettings.AppSettings["FromDisplay"].ToString();
                List<string> toUsers = new List<string>();
                toUsers.Add(objSysCustomerEntity.CustomerMail);
                mailCfg.Tousers = toUsers;
                mailCfg.Touccs = new List<string>();
                mailCfg.Subject = "服务反馈调查";

                string strBody = "";
                string strUrl = UIHelper.BaseUrl + "SystemManage/Investigate/FillPage.aspx?id=" + objTicketEntity.Id;
                strBody += "请添加评价" + "<br />";
                strBody += "网址:" + "<a href=" + "\"" + strUrl + "\"></a>" + "<br />";
                strBody += System.Configuration.ConfigurationSettings.AppSettings["BodyBottom"].ToString() + "<br />";
                mailCfg.Body = strBody;
                return mailCfg;
            }

     public static bool Sendmail(MailCfg mailCfg)
            {
                try
                {
                    MailMessage mailMessage = new MailMessage();
                    mailMessage.From = new MailAddress(mailCfg.Fromuser, mailCfg.Fromdisplay);//发件人
                    for (int i = 0; i < mailCfg.Tousers.Count; i++)//收件人
                    {
                        string address = mailCfg.Tousers[i].Trim();
                        if (address != "")
                            mailMessage.To.Add(new MailAddress(address));
                    }

                    for (int i = 0; i < mailCfg.Touccs.Count; i++)//抄送
                    {
                        string address1 = mailCfg.Touccs[i].Trim();
                        if (address1 != "")
                            mailMessage.To.Add(new MailAddress(address1));
                    }
                    mailMessage.Subject = mailCfg.Subject;//标题
                    mailMessage.Body = mailCfg.Body;    // 内容
                    mailMessage.IsBodyHtml = true;
                    mailMessage.BodyEncoding = Encoding.UTF8;
                    SmtpClient sc = new SmtpClient(mailCfg.Host);
                    sc.DeliveryMethod = SmtpDeliveryMethod.Network;
                    sc.UseDefaultCredentials = false;
                    sc.EnableSsl = false;
                    sc.Credentials = new NetworkCredential(mailCfg.Username, mailCfg.Userpwd);
                    sc.Send(mailMessage);
                    mailMessage.Dispose();
                    return true;
                }
                catch
                {
                    return false;
                }
            } 

     


    梅小虎
    2010年4月14日 7:13

答案

全部回复