我正在尝试通过hostgator中的邮件发送联系表单数据

时间:2012-05-01 16:33:54

标签: c# email

我正在尝试通过在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 = "";

    }
}

1 个答案:

答案 0 :(得分:1)

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

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