通过Outlook发送电子邮件(托管在自定义域上)

时间:2013-07-26 01:18:26

标签: email outlook smtp

我在 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);
                }
            }

1 个答案:

答案 0 :(得分:3)

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

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);