SMTP in Web.config?

Discussion in 'ASP.NET WebServices' started by Pointeman, Sep 29, 2010.

  1. Is this the correct code for DiscountAsp Smtp in Web.config?

    <system.net>
    <mailSettings>
    <smtp from="[email protected]">
    <network host="smtp.mydomainname.net" password="discountasploginpassword" userName="discountasploginusername"/>
    </smtp>
    </mailSettings>
    </system.net>


    I get the smpt into the class like so:

    Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
    System.Net.Configuration.MailSettingsSectionGroup settings = (System.Net.Configuration.MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");
    Smtp = settings.Smtp.Network.Host.ToString();
     
  2. ..Like this with "localhost", without the actual host address:

    <system.net>
    <mailSettings>
    <smtp from="[email protected]" deliveryMethod="Network">
    <network host="localhost" port="25" password="password" userName="[email protected]" />
    </smtp>
    </mailSettings>
    </system.net>
     
  3. 1. The 'username' is my actual email address from my account settings?
    2. The 'password' is my discountasp login password?
     
  4. dmitri

    dmitri DiscountASP.NET Staff

    There is no authentication required for localhost. When sending emails from a web application using localhost smtp server, please leave user name and password blank.
     
  5. It's working now, thanks...
     
  6. ...Good job
    I should have mentioned you only need the username and password if you're running Health Monitoring and are receving mail from the services. ;-)
     

Share This Page