当前位置: 首页 > news >正文

农村建设设计网站首页做p2p网站的公司

农村建设设计网站首页,做p2p网站的公司,网页制作个人介绍代码,建设自己的网站有钱赚么最近使用.net的System.Web.Mail发送邮件在服务器上失败,经过多次尝试,终于解决了这个问题: 一般System.Web.Mail是.net自带的发送邮件的库.但发现失败的原因有几种,贴出来给大家参考一下: <% Page Language"C#" %> <script language"C#" runat&…

 最近使用.net的System.Web.Mail发送邮件在服务器上失败,经过多次尝试,终于解决了这个问题:

一般System.Web.Mail是.net自带的发送邮件的库.但发现失败的原因有几种,贴出来给大家参考一下:

<%@ Page Language="C#" %>
<script language="C#" runat="server">

void Page_Load()
{
// 使用一个SMTP的服务器,并且通过验证
  System.Web.Mail.MailMessage myEmail = new System.Web.Mail.MailMessage();
 myEmail.From = "username@126.com";
 myEmail.To = "aim@eyou.com";
 myEmail.Subject = "测试";
 myEmail.BodyFormat = System.Web.Mail.MailFormat.Text;
 myEmail.Body = "看到了么?";
 // 通过SMTP服务器验证
 myEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
 myEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "username");
 myEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "userpassword");
 System.Web.Mail.SmtpMail.SmtpServer = "smtp.126.com";
 System.Web.Mail.SmtpMail.Send(myEmail);
 lblMailStatus.Text = "Mail successfully sent.";
}

</script>

<html>
<body>

<asp:Label id="lblMailStatus" runat="server" />

</body>
</html>

这个是常见的发送方式,

案例一:见到网上有些资料缺少

 // 通过SMTP服务器验证
 myEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
 myEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "username");
 myEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "userpassword");

这一部分,是失败原因其中之一.有些邮件服务器(smtp)需要用户验证.

附CdoConfiguration相关属性参考:(转自:http://dev.csdn.net/article/78/78245.shtm)
public abstract class CdoConfiguration
{
      // Fields
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoAutoPromoteBodyParts = "http://schemas.microsoft.com/cdo/configuration/autopromotebodyparts";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoFlushBuffersOnWrite = "http://schemas.microsoft.com/cdo/configuration/flushbuffersonwrite";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoHTTPCookies = "http://schemas.microsoft.com/cdo/configuration/httpcookies";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoLanguageCode = "http://schemas.microsoft.com/cdo/configuration/languagecode";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoNNTPAccountName = "http://schemas.microsoft.com/cdo/configuration/nntpaccountname";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoNNTPAuthenticate = "http://schemas.microsoft.com/cdo/configuration/nntpauthenticate";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoNNTPConnectionTimeout = "http://schemas.microsoft.com/cdo/configuration/nntpconnectiontimeout";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoNNTPServer = "http://schemas.microsoft.com/cdo/configuration/nntpserver";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoNNTPServerPickupDirectory = "http://schemas.microsoft.com/cdo/configuration/nntpserverpickupdirectory";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoNNTPServerPort = "http://schemas.microsoft.com/cdo/configuration/nntpserverport";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoNNTPUseSSL = "http://schemas.microsoft.com/cdo/configuration/nntpusessl";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoPostEmailAddress = "http://schemas.microsoft.com/cdo/configuration/postemailaddress";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoPostPassword = "http://schemas.microsoft.com/cdo/configuration/postpassword";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoPostUserName = "http://schemas.microsoft.com/cdo/configuration/postusername";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoPostUserReplyEmailAddress = "http://schemas.microsoft.com/cdo/configuration/postuserreplyemailaddress";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoPostUsingMethod = "http://schemas.microsoft.com/cdo/configuration/postusing";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoSaveSentItems = "http://schemas.microsoft.com/cdo/configuration/savesentitems";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoSendEmailAddress = "http://schemas.microsoft.com/cdo/configuration/sendemailaddress";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoSendPassword = "http://schemas.microsoft.com/cdo/configuration/sendpassword";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoSendUserName = "http://schemas.microsoft.com/cdo/configuration/sendusername";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoSendUserReplyEmailAddress = "http://schemas.microsoft.com/cdo/configuration/senduserreplyemailaddress";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoSendUsingMethod = "http://schemas.microsoft.com/cdo/configuration/sendusing";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoSMTPAccountName = "http://schemas.microsoft.com/cdo/configuration/smtpaccountname";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoSMTPAuthenticate = "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoSMTPConnectionTimeout = "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoSMTPServer = "http://schemas.microsoft.com/cdo/configuration/smtpserver";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoSMTPServerPickupDirectory = "http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoSMTPServerPort = "http://schemas.microsoft.com/cdo/configuration/smtpserverport";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoSMTPUseSSL = "http://schemas.microsoft.com/cdo/configuration/smtpusessl";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoURLGetLatestVersion = "http://schemas.microsoft.com/cdo/configuration/urlgetlatestversion";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoURLProxyBypass = "http://schemas.microsoft.com/cdo/configuration/urlproxybypass";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoURLProxyServer = "http://schemas.microsoft.com/cdo/configuration/urlproxyserver";
      [MarshalAs(UnmanagedType.BStr)]
      public const string cdoUseMessageResponseText = "http://schemas.microsoft.com/cdo/configuration/usemessageresponsetext";
}
例子代码如下:
   MailMessage myMail = new MailMessage();
   myMail.From = emailFrom;
   myMail.To = emailTo;
   myMail.Subject = subject;
   myMail.Body = sb.ToString();
   myMail.BodyFormat = MailFormat.Html;
   myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing","2");
   myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendemailaddress",emailFrom);
   myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpuserreplyemailaddress",emailFrom);
   myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpaccountname",userName);
   myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",Your 163.com's userName);
   myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",your 163.com's password);
   myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate","1");
   myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver","smtp.163.com");
   //SmtpMail.SmtpServer = "smtp.163.com";
   SmtpMail.Send(myMail);

案例二:

已经加上smtp验证,仍然发送失败:原因应该是IIS的设置

运行后系统提示错误信息:

Email Fail
Could not access 'CDO.Message' object.
Here is the full error message output:
System.Web.HttpException: Could not access 'CDO.Message' object. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x8004020F): The server rejected one or more recipient addresses. The server response was: 550 5.7.1 Unable to relay for 12321323@mobile.att.net

检查SMTP SERVICE,正常,估计是权限设置问题。打开IIS ADMIN,右键点击SMTP VIRTUAL SERVER,选择属性,在ACCESS中点RELAY,增加127.0.0.1。一路OK回去。

这时候再运行程序,邮件发送成功。

转自:http://blog.joycode.com/cafecat/archive/2004/11/06/38186.aspx

案例三,就是我所遇到的问题,和同事调试多次之后才发现:服务器为了安全,把一些控件(dll)禁用了.

抛出无法加载Dll的错误.

最后发现,发送邮件需要调用到msado15.dll.而ADO被禁用.导致出错.

希望这些能帮到使用System.Web.Mail的人:)

 

 

http://www.yayakq.cn/news/351376/

相关文章:

  • wordpress插件+手机版给甜品网站做seo
  • discuz 门户网站模板网络营销第2版课后答案
  • reeyee网站建设西安做效果图的公司
  • 在哪里可以自己建网站中文网站建设技术解决方案
  • 广东个人网站备案怎样创建公司网站
  • 上海网站建设工作室公司开发网站建设价格
  • 南京市建设档案馆网站洛阳便宜网站建设
  • 电子商务网站制作教程湘潭做网站价格优选磐石网络
  • 网站域名如何备案信息品牌设计公司取名
  • 网站开发怎么谈设计师网址推荐
  • 如何查找网站死链html基础菜鸟教程
  • 南昌个人做网站网站运营每天做的
  • 网站建设心得感想seo网站建设接单
  • 网站后台html模板南京中企动力有限公司
  • 鄂州商城网站建设关键词优化过程
  • 怎么上不到建设银行网站小程序开发 深圳
  • 哪个网站做汽车保养比较好网站搭建上海
  • 山东省建设监理协会网站打不开宁波门户网站建设
  • 做网站公司有哪些纺织品做外贸一般在哪个网站上
  • 做营销策划要用到哪些网站网站建设项目描述范文
  • 品牌网站建设找顺的iis一个文件夹配置多个网站
  • 网站建设人员组成wordpress自定义界面
  • 爱站长尾关键词挖掘工具中国五百强企业排名表
  • 石家庄网站建设技术支持金华职院优质校建设网站
  • 英文网站建设的问题东莞网站建设(信科网络)
  • 深圳建站公司模板高德是中国的还是外国的
  • 网站 竞争分析深圳海洋网络做网站
  • 济南哪里做网站机械设计最好的三维软件
  • 国内网站不备案厦门网站推广公司
  • wordpress 导航站模板下载地址网站如何百度收入