Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dmitriy 168 posts 588 karma points
    Oct 19, 2018 @ 12:08
    Dmitriy
    0

    How to get smtp settings (<mailSettings>) from Web.config?

    Hello, Umbracians.

    I want to use settings from Web.config to make my little custom email-module work.

    There is ConfigurationManager.GetSection("sectionName"), I tried input several paths, but it returns null anyway.

    How to get it properly? Or, for my purpose: how to edit MailMessage properties that uses in library.SendMail()

  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    Oct 19, 2018 @ 12:17
    Dan Diplo
    101

    SMTP settings aren't an Umbraco specific thing - they are a standard .NET setting. So you can access them directly from the SMTP client class.

    So, add a reference to;

    @using System.Net.Mail
    

    Then you can go...

    SmtpClient client = new SmtpClient();
    string host = client.Host;
    

    Use IntelliSense to see all the properties you can access on the client instance.

    Docs: https://docs.microsoft.com/en-us/dotnet/api/system.net.mail.smtpclient

  • Dmitriy 168 posts 588 karma points
    Oct 22, 2018 @ 10:52
    Dmitriy
    0

    Hi, Dan

    I knew about that class, but haven't knew about it scans configs right in constructor.

    Many thanks! You saved my day

Please Sign in or register to post replies

Write your reply to:

Draft