ASP.NET MVC SMTP错误发送邮件问题

时间:2018-11-26 10:40:54

标签: asp.net asp.net-mvc smtp

我已经编辑了webconfig文件,但是我有SmtpException "error sending mail"。我的域端口是25。我已经仔细检查过。这是我的代码。什么问题?谢谢。

public void SendEmail(string toAddress, string fromAddress,string subject, string message)
    {
        try
        {
            using (var mail = new MailMessage())
            {


                mail.From = new MailAddress(fromAddress);
                mail.To.Add(new MailAddress(toAddress));
                mail.Subject = subject;
                mail.Body = message;
                mail.IsBodyHtml = true;

                try
                {
                    using (var smtpClient = new SmtpClient())
                    {
                        smtpClient.Host = "webmail.domain.com";
                        smtpClient.Port = 25;
                        smtpClient.Credentials = new NetworkCredential("blabla@domain.com", "pass");
                        smtpClient.Send(mail);
                    }

                }
                    mail.Dispose();   
            }
        }

0 个答案:

没有答案