0

我正在尝试通过在 hostgator 中创建 dotnetnuke 模块来发送邮件,但邮件不起作用。请给我任何有用的建议。

protected void btnSubmit_Click(object sender, EventArgs e)
    {   
        string Fname = txtFname.Text;
        string Lname = txtLname.Text;
        string Email = txtEmail.Text;
        string Telephone = txtTelephone.Text;
        string comments = txtComments.Text;
        MailMessage newmail = new MailMessage(ConfigurationManager.AppSettings["FromEmailHelpForm"].ToString(), ConfigurationManager.AppSettings["ToEmailHelpForm"].ToString());
        newmail.Subject = "Contact Form Notification";
        newmail.IsBodyHtml = true;
        newmail.Body = "<table><tr><td>First Name:<td><td>' " + Fname + " '</td><tr><tr><td>Last Name:<td><td>' " + Lname + " '</td><tr><tr><td>Primary Email Address: <td><td>' " + Email + " '</td><tr><tr><td>Telephone: <td><td>' " + Telephone + " '</td><tr><tr><td>Comments: <td><td>' " + comments + " '</td><tr></table>";

        SmtpClient mail = new SmtpClient("localhost");
        try
        {
            if (CaptchaControl1.IsValid)
            {
                mail.Send(newmail);
                reset();
                pnlMessage.Visible = true;
                pnlform.Visible = false;
                lblError.Text = "Thankyou for submiting the form we will get you soon";
                lblError.ForeColor = System.Drawing.Color.Blue;
            }
            else
            {
                lblError.Text = "Invalid Security Code ";
                lblError.ForeColor = System.Drawing.Color.Red;
            }

        }
        catch (Exception err)
        {
            lblError.Text = "An error Occured -->"+err.Message;
            lblError.ForeColor = System.Drawing.Color.Red;
        }
    }

    public void reset()
    {
        txtFname.Text = "";
        txtLname.Text = "";
        txtTelephone.Text = "";
        txtEmail.Text = "";
        txtComments.Text = "";

    }
}
4

1 回答 1

1

为了发送电子邮件,您需要一个真正的SMTP 服务器。需要设置 SMTPClient 的 Host 属性。

您可以使用现有的 SMTP 中继服务器,例如 GMail,也可以将 IIS 配置为虚拟 SMTP 服务器。

于 2012-05-01T16:51:03.680 回答