开发者社区> 问答> 正文

電郵推送加密端口 465,587 無法連接 C# .net core 2.1

下面的代碼如果使用80 端口沒問題,但是 端口 用 465 跟587 就出問題。
Inner Exception 1:
IOException: Unable to read data from the transport connection: The connection was closed.  


public void SendEmail(string email, string subject, string content)
        {
            if (!SmtpServerEnabled) {
                return;
            }
            SmtpClient client = new SmtpClient(this.SmtpServer,587)
            {
                //UseDefaultCredentials = false,
                Credentials = new NetworkCredential(this.SmtpUserName,this.SmtpPassword)
            };

            client.EnableSsl = true;
            
            MailMessage mailMessage = new MailMessage
            {
                From = new MailAddress(this.SmtpSender)
            };

            
            mailMessage.From = new MailAddress(this.SmtpUserName);
            mailMessage.To.Add(email);
            mailMessage.IsBodyHtml = true;
            mailMessage.Body = content;
            mailMessage.Subject = subject;

            try
            {
                client.Send(mailMessage);
            }
            catch (System.Exception e) {
                System.Console.WriteLine(e.InnerException?.Message);
            }



        }

展开
收起
ags 2019-02-26 16:00:01 809 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
基于可信计算与加密计算 打造云上原生计算安全 立即下载
\"视频服务特色解决方案——直播连麦与点播加密 \" 立即下载
量子加密通信技术 立即下载