0
ارسال ایمیل در ASP.NET
با سلام و وقت بخیر.برای ارسال ایمیل از نرم افزار و ارتباط با Mailserver کد زیر رو نوشتم: مسول شبکه گفتن که باید برای تمام certification ها مقدار true برگرده منم کد زیر رو اضافه کردم
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
using System;
using System.Collections.Generic;
using System.Net.Mail;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;
public partial class SendEmail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void button1_Click(object sender, EventArgs e)
{
try
{
SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
//client.Host = "mail.scu.ac.ir";
client.Host = "192.168.168.20";
client.Port = 465;
client.Credentials = new System.Net.NetworkCredential("rms@scu.ac.ir", "****");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
MailMessage mail = new MailMessage();
//Setting From , To and CC
mail.From = new MailAddress("***@scu.ac.ir", "RMS");
mail.To.Add(new MailAddress("***@scu.ac.ir"));
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
client.Send(mail);
Response.Write("<script>alert('mail Send');</script>");
Label4.Text = "mail Send";
}
catch (Exception ex)
{
//Response.Write("<script>alert(ex.ToString());</script>");
Label4.Text = (ex.ToString());
}
}
}
اما هنوز خطا زیر رو برمیگردونه
System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed. at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine) at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine) at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller) at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message)