我曾經使用c#在aspx中創建了一個註冊頁面。我已經寫了這個簡單的代碼來註冊後發送郵件,但它不起作用。我知道這很容易受到SQL注入的影響,但請忽略,我只是想測試電子郵件的發送方式。 它是顯示遠程名稱無法解析錯誤 :「www.blablabla.foo」嘗試使用c#從aspx頁面發送電子郵件時出錯無法解析遠程名稱:'www.blablabla.foo'
請告訴我什麼是錯誤,什麼是修改我不得不作出這樣我就可以發送電子郵件。
FileUpload1.PostedFile.SaveAs(Server.MapPath(".") + "//uploadimage//" + str);
string path = "../Alumni/uploadimage/" + str.ToString();
con.Open();
SqlCommand cmd = new SqlCommand("insert into highly-sql-injection-prone-table...", con);
cmd.ExecuteNonQuery();
con.Close();
MailMessage msg;
SqlCommand cmd1 = new SqlCommand();
string ActivationUrl = string.Empty;
string emailId = string.Empty;
cmd1.Parameters.AddWithValue("@Name", TextBox5.Text.Trim());
cmd1.Parameters.AddWithValue("@EmailId", TextBox1.Text.Trim());
cmd1.Parameters.AddWithValue("@Password", TextBox3.Text.Trim());
if (con.State == ConnectionState.Closed)
{
con.Open();
}
cmd.ExecuteNonQuery();
msg = new MailMessage();
SmtpClient smtp = new SmtpClient();
emailId = TextBox1.Text.Trim();
msg.From = new MailAddress("[email protected]");
msg.To.Add(emailId);
msg.Subject = "Confirmation E-mail";
msg.Body = "Hi";
msg.IsBodyHtml = true;
smtp.Credentials = new NetworkCredential("[email protected]", "***************");
smtp.Port = 587;
smtp.Host = "smtp.blablabla.foo";
smtp.EnableSsl = true;
smtp.Send(msg);
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message",
"alert('Confirmation Link to activate your account has been sent to your email address');", true);
con.Close();
Session["New"] = TextBox1.Text;
Response.Redirect("Successfull.aspx");
代理服務器未啓用可能是 –
當我在stjosephschoolrkl.org上使用'type = MX'做'nslookup'時,我得到MX條目爲'mail.stjosephschoolrkl.org'。也許你應該檢查'smtp.Host'是否設置不正確。 –