ارسال ایمیل در سی شارپ با استفاده از اکانت مایکروسافت و افیس 365
نحوه ارسال ایمیل در سی شارپ
//failure sending mail c# smtpclient
public void SendMail(string subject, string to, string displayName, string message)
{
    var credentials = new NetworkCredential(account.Email, account.Password);
    var mail = new MailMessage()
    {
        From = new MailAddress(account.Email, displayName),
        Subject = subject,
        Body = message,
    };
    mail.IsBodyHtml = true;//If you want to send mail in html format
    mail.To.Add(new MailAddress(to));
    var client = new SmtpClient() { Port = account.Port ?? 0, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Host = account.Server, EnableSsl = true, Credentials = credentials };
    client.Send(mail);
}
تنظیمات
account.Email: [your email account]
account.Password: [your email password]
Port: 587
Host: smtp.office365.com
اگر به ارور Unable to read data from the transport connection: net_io_connectionclosed برخورد کردین با کد زیر مشکل را حل کنید
SmtpClientSystem.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
این کد را به اول فانکشن خود اضافه کنید
پایان
 
	 
	 
                
                