我在发送电子邮件时遇到问题我输入了有效的电子邮件但是当我点击提交按钮时我收到此错误,错误:发送邮件失败
这是我的代码(web.Config)
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="Soha@sohasys.com">
<!-- Default Port is [25] -->
<!-- Specific Port for Gmail is [587] NOT!!! [995]-->
<network defaultCredentials="false" host="mail.Sohasys.com" enableSsl="true" userName="Soha@sohasys.com" password="XXXX" port="587"/>
</smtp>
</mailSettings>
</system.net>
这是我的代码
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
try
{
System.Net.Mail.MailMessage oMailMessage = new System.Net.Mail.MailMessage();
oMailMessage.IsBodyHtml = true;
oMailMessage.Priority = System.Net.Mail.MailPriority.Normal;
oMailMessage.DeliveryNotificationOptions = System.Net.Mail.DeliveryNotificationOptions.Never;
System.Net.Mail.MailAddress oMailAddress = null;
oMailAddress =
new System.Net.Mail.MailAddress(txtEmail0.Text, ttxtPhone.Text, System.Text.Encoding.UTF8);
oMailMessage.From = oMailAddress;
oMailMessage.Sender = oMailAddress;
oMailMessage.ReplyTo = oMailAddress;
oMailAddress =
new System.Net.Mail.MailAddress("Soha@sohasys.com", "", System.Text.Encoding.UTF8);
oMailMessage.To.Add(oMailAddress);
// oMailMessage.CC
// oMailMessage.Bcc
oMailMessage.SubjectEncoding = System.Text.Encoding.UTF8;
oMailMessage.Subject = "(From WebSite)" + " : " + txtUsername.Text;
oMailMessage.BodyEncoding = System.Text.Encoding.UTF8;
oMailMessage.Body = txtBody.Text;
System.Net.Mail.SmtpClient oSmtpClient = new System.Net.Mail.SmtpClient("Soha@sohasys.com", 587);
oSmtpClient.EnableSsl = true;
oSmtpClient.Timeout = 100000;
// oSmtpClient.UseDefaultCredentials = false;
// ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
oSmtpClient.Send(oMailMessage);
Label5.Visible = true;
Label5.Text = "Your Email Send SuccesFully.";
}
catch (System.Exception ex)
{
Response.Write("Error: " + ex.Message);
}
}
}