C# SMTP Send Email From Local Machine

Discussion in 'ASP.NET / ASP.NET Core' started by mapyourhike, Apr 28, 2009.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Since I use my local machine for dev/testing, I currently testing the ability to send registration and other email communications to users. I'm setting my SMTP client to the smtp.domainname.com provided by discount asp.

    I can create the SmtpClient with no problem as shown below:

    mailClient = new SmtpClient(MapYourHike.Shared.Common.getConfigKey("SMTPServer"), 25);

    However, when I attempt to send the email using the following code:

    string expectionMsg = "";
    try
    {
    mailClient.Send(message);
    }
    catch (SmtpException ex)
    {
    expectionMsg =
    "SmtpException has occured: " + ex.Message;
    throw new ApplicationException(expectionMsg);
    }

    The following exception is thrown:

    {"Mailbox unavailable. The server response was: <emailddress> No such user here"}

    Do I need to set credentials to my mailbox in code?

    What do you guys think?]

    Thx for the input...
     
  2. Try using 'localhost' as the smtp server. This is the web servers smtp service and it's the preferred method of sending out email with a web page. 'Localhost' will not require any smtp authentication to be passed by the application.
     
  3. Thanks but I think I got it; I have to set the username & pwd for the account I'm using to send mail.

    Tested it out and works great from my local machine

    public Email()
    {
    mailClient = new SmtpClient();
    mailClient.Host = MapYourHike.Shared.Common.getConfigKey("SMTPServer");
    mailClient.Port = 587;
    mailClient.UseDefaultCredentials = false;
    mailClient.Credentials = new NetworkCredential(MapYourHike.Shared.Common.getConfigKey("WebMasterAddress"), MapYourHike.Shared.Common.getConfigKey("WebMasterPassword"));
    }
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page