我已经尝试了一切,但它一直在给我这个信息,而所有信息都是正确的(我认为是这样)。
这是错误:
System.Net.Mail.SmtpException:地址的主机名无效:yakovmora1@gmail.com。System.ArgumentException:在索引 9 处找到无效的 Unicode 代码点。参数名称:System.Text.Normalization.Normalize 处的 strInput(String strInput,NormalizationForm normForm)
我在 ASPX.CS 中的代码是:
protected void Sbutton_Click(object sender, EventArgs e)
{
string Name = Request.Form["Name"];
string email = Request.Form["email"];
string message = Request.Form["Message"];
if (CheckFields(Name, email, message, ref Label1) == true)
{
try
{
MailMessage myEmail = new MailMessage()
{
Subject = "Message from website user: [" + Name + "]",
Body = "Email: " + email + Environment.NewLine + Environment.NewLine + message,
IsBodyHtml = false,
From = new MailAddress(email, Name),
};
myEmail.To.Add(new MailAddress("yakovmora1@gmail.com", "IsraeCoreLx"));
SmtpClient server = new SmtpClient();
server.Send(myEmail);
Label1.Text = "Message Sent";
}
catch (Exception ex)
{
Label1.Text = "error sending message <br/><br/>" + ex.ToString();
}
if (Label1.Text != "Message Sent")
{
Label1.Text = "trying again";
#region trying again
try
{
MailMessage myEmail = new MailMessage()
{
Subject = "Message from website user: [" + Name + "]",
Body = "Email: " + email + Environment.NewLine + Environment.NewLine + message,
IsBodyHtml = false,
From = new MailAddress(email, Name)
};
myEmail.To.Add(new MailAddress("yakovmora1@gmail.com", "IsraeCoreLx"));
SmtpClient server = new SmtpClient();
server.Port = 25;
server.Send(myEmail);
Label1.Text = "Message Sent";
}
catch (Exception ex)
{
Label1.Text = "error sending message <br/><br/>" + ex.ToString();
}
#endregion
}
if (Label1.Text == "Message Sent")
{
CleanFields( Name, email, message ,ref Label1);
}
}
}
private void CleanFields(string Name, string email, string message, ref Label Label1)
{
Request.Form["Name"] = "";
Request.Form["email"] = "";
Request.Form["message"] = "";
}
private Boolean CheckFields(string Name, string email, string message, ref Label Label1)
{
if (Name != "")
{
if (IsEmailValid(email) == true)
{
if (message != "")
return true;
else
Label1.Text = "Your message is empty.";
}
else
{
Label1.Text = "Your email is invalid.";
}
}
else
{
Label1.Text = "Please fill in your Name.";
}
return false;
}
private Boolean IsEmailValid(string EmailAddr)
{
if (EmailAddr != null || EmailAddr != "")
{
Regex n = new Regex("(?<user>[^@]+)@(?<host>.+)");
Match v = n.Match(EmailAddr);
if (!v.Success || EmailAddr.Length != v.Length)
return false;
else
return true;
}
else
return false;
}