none
Send email via SMTP in Outllok.com for custom domain

    Question

  • I have unit test that tests email sending, which do not works.

    I SMTP settings are below

    Host: smtp.live.com

    Posrt: 25/465/587

    EnableSsl: Yes

    Username: XXX@tiksn.com

    Password: XYZ

    Here is the code

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

    Wednesday, July 24, 2013 10:28 PM

Answers

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


    • Marked as answer by TIKSN Sunday, July 28, 2013 2:10 AM
    Sunday, July 28, 2013 2:09 AM

All replies

  • Where is Outlook involved in this? If you want to send from Outlook, and this is a forum for Outlook development, use the Outlook object model and not System.Net.Mail.

    Ken Slovak MVP - Outlook

    Thursday, July 25, 2013 2:08 PM
  • I mean Outlook.com not the Office Outlook client.

    Friday, July 26, 2013 1:49 AM
  • In that case this is totally the wrong forum. I'd post in either a .NET forum or an Outlook.com forum. The expertise here is in Outlook the client development.

    Ken Slovak MVP - Outlook

    Saturday, July 27, 2013 6:23 PM
  • 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);


    • Marked as answer by TIKSN Sunday, July 28, 2013 2:10 AM
    Sunday, July 28, 2013 2:09 AM
  • It is not working, throwing an error when using in WordPress  
    Sunday, July 28, 2013 11:22 AM