0

我在tiksn.com域上有Outlook.com支持的电子邮件。我想发送一封电子邮件,但没有成功。这是代码。

更新:这是错误消息:SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.7.0 必须先发出 STARTTLS 命令

using (System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage())
            {
                mailMessage.From = new System.Net.Mail.MailAddress(Preference.Email.Default.SystemAddress);
                mailMessage.To.Add(Preference.Email.Default.ContactAddress);
                mailMessage.ReplyToList.Add(UserAddress);
                mailMessage.Sender = UserAddress;
                mailMessage.Subject = Subject;
                mailMessage.IsBodyHtml = false;
                mailMessage.Body = Message;
                mailMessage.DeliveryNotificationOptions = System.Net.Mail.DeliveryNotificationOptions.Delay | System.Net.Mail.DeliveryNotificationOptions.OnFailure | System.Net.Mail.DeliveryNotificationOptions.OnSuccess;
                mailMessage.Priority = System.Net.Mail.MailPriority.Normal;

                using (System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient())
                {
                    smtpClient.Credentials = new System.Net.NetworkCredential(Preference.Email.Default.SystemAddress, Preference.Email.Default.SystemPassword);
                    smtpClient.DeliveryFormat = System.Net.Mail.SmtpDeliveryFormat.International;
                    smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                    //smtpClient.EnableSsl = true;
                    smtpClient.Host = "smtp.live.com";
                    smtpClient.Port = 25;
                    //smtpClient.Port = 587;
                    //smtpClient.Port = 465;
                    smtpClient.UseDefaultCredentials = false;

                    smtpClient.Send(mailMessage);
                }
            }
4

1 回答 1

3

最后我找到了解决方案。首先,您必须指定凭据设置,例如主机、帖子等。只有在初始化网络凭据对象之后。

smtpClient.EnableSsl = true;
smtpClient.Host = "smtp.live.com";
smtpClient.Port = 587;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new System.Net.NetworkCredential(Preference.Email.Default.SystemAddress, Preference.Email.Default.SystemPassword);
于 2013-07-28T02:10:37.590 回答