0

I have Outlook.com powered email on tiksn.com domain. I want to send an email but was not succeed. Here is the code.

Update: Here is the error message: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first

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);
                }
            }
TIKSN
  • 615
  • 1
  • 6
  • 24
  • You need to give us more details about "was not succeeded". You're trying to use "smtp.live.com" as your SMTP server. Look at this link: http://stackoverflow.com/questions/298363/how-can-i-make-smtp-authenticated-in-c-sharp – paulsm4 Jul 26 '13 at 01:28

1 Answers1

3

Finally I found the solutions. First you have to specify settings of credentials, like host, post, etc. Only after that initialize Network Credential object.

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);
TIKSN
  • 615
  • 1
  • 6
  • 24