Error sending email to external accounts

Discussion in 'Email' started by mcwheeler, May 17, 2012.

  1. I am trying to setup a Forgot Password page that will email the user a temporary password. If I set the to email to an internal address, it works, but if it is set to any external address it does not.

    I get a SmtpFailedRecipientException with a message of "Mailbox unavailable. The server response was: <[email protected]> No such user here".

    He is my code:

    using System;
    using System.Collections.Generic;
    using System.Net;
    using System.Net.Mail;
    using SC.TAS.OKTLE.Common.BaseClasses;
    using SC.TAS.OKTLE.Common.Interfaces;
    using SC.TAS.OKTLE.Common.Interfaces.Email;
    using SC.TAS.OKTLE.Common.RequestResponseObjects;

    namespace SC.TAS.OKTLE.Common.Utility
    {

    public class Emailer : IEmailer
    {

    private readonly SettingsReaderBase _settingsReader;
    private readonly ILogger _logger;

    public Emailer()
    {
    _settingsReader = DependencyResolver.SettingsReader;
    _logger = DependencyResolver.Logger;
    }

    #region IEmailer Members

    public ServiceResponse Send(string to, string subject, string body)
    {
    ServiceResponse response = new ServiceResponse();
    SmtpClient mailClient = new SmtpClient();
    try
    {
    NetworkCredential networkCredential = new NetworkCredential("[email protected]", "********", "oktledev.com");
    mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
    mailClient.EnableSsl = false;
    mailClient.Host = "mail.oktledev.com";
    mailClient.UseDefaultCredentials = false;
    mailClient.Credentials = networkCredential;

    mailClient.Send("[email protected]", "[email protected]", subject, body);
    }
    catch (SmtpException smtpException)
    {
    _logger.LogError(smtpException);
    response.ApplicationErrors = new List<string> { "There was an error sending the email." };
    return response;
    }
    return response;
    }

    #endregion
    }
    }

    Please advise as I have tried suggestions in other post and have not found an answer.

    Thank you,

    Michael Wheeler
     
  2. Elshadriel

    Elshadriel Winhost Staff

    Last edited by a moderator: Oct 14, 2015

Share This Page