asp.NET不是通过localhost发送邮件

时间:2014-01-24 22:29:52

标签: c# asp.net .net .net-1.1

我对使用asp.NET 1.1的服务器的联系表单代码有疑问,遗憾的是无法升级.NET。这段代码完美地运用到今天。服务器有一些变化,我不知道发生了什么。我唯一的猜测是我不再拥有localhost的权限。是否有可能改变它在.NET 1.1上的发送方式?我试过使用gmail帐户,但我只是因为SSL和端口而出错。

我的代码:

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Mail" %>
<script runat="server">    
    void btnSubmit_Click(Object sender, EventArgs e) {

        MailMessage objEmail = new MailMessage();
        objEmail.To = "my_mail@gmail.com";
        objEmail.From = txtFrom.Text;
        objEmail.Cc = txtCc.Text;
        objEmail.Subject = "Contact";
        objEmail.Body = "Message: " + txtComments.Text + " <br> " + "name:" + txtName.Text;
        objEmail.Priority = MailPriority.High;
        objEmail.BodyFormat = MailFormat.Html;

        // Make sure you have appropriate replying permissions from your local system
                SmtpMail.SmtpServer = "localhost";

        try{
            SmtpMail.Send(objEmail);
                        }
        catch (Exception exc){
                        }
    }
</script>

删除try / catch方法后:

来源错误:

Line 16:        // Make sure you have appropriate replying permissions from your local system
Line 17:                 SmtpMail.SmtpServer = "localhost";
Line 18: SmtpMail.Send(objEmail);
Line 19:        
Line 20:     }

堆栈追踪:

[COMException (0x80040213): Nie powiodlo sie polaczenie warstwy transportu z serwerem.
]

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) +0
   System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) +473
   System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args) +58

[HttpException (0x80004005): Could not access 'CDO.Message' object.]
   System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args) +113
   System.Web.Mail.CdoSysHelper.Send(MailMessage message) +1569
   System.Web.Mail.SmtpMail.Send(MailMessage message) +150
   ASP.div_aspx.btnSubmit_Click(Object sender, EventArgs e) in e:\helm\www2\wspolnicy.com\wwwroot\div.aspx:18
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain() +1273

0 个答案:

没有答案