Archived Forum Post

Index of archived forum posts

Question:

Use mailSsettings from app.config / web.config in MailMan

Sep 09 '13 at 12:05

Tried to find the answer to this in the documentation / examples, but haven't found it.

In the configuration file of an application or website you can set the default mailsettings: <system.net> <mailsettings> <smtp> <network host="xxx" port="25" username="xxx" password="xxx"/> </smtp> </mailsettings> </system.net>

Is it possible to let MailMan use these settings by default or do you need always need to define the host/port/username/password after creating the MailMan object?


Answer

Any reply for this question?


Answer

It is extremely simple to write a few lines of code that loads the XML and uses the values found within to set the Chilkat MailMan properties. I would not make sense for Chilkat to include this in the API, because Chilkat supports many different programming languages and operating systems and app.config and web.config make no sense except for in certain environments.

Here is some sample C# code:

            bool success = xml.LoadXmlFile("c:/aaworkarea/config.xml");

        string host = xml.ChilkatPath("mailsettings|smtp|network|(host)");
        string username = xml.ChilkatPath("mailsettings|smtp|network|(username)");
        string password = xml.ChilkatPath("mailsettings|smtp|network|(password)");
        int port = Convert.ToInt32(xml.ChilkatPath("mailsettings|smtp|network|(port)"));

        // Alternatively:
        Chilkat.Xml network = xml.FindChild("mailsettings").FindChild("smtp").FindChild("network");
        string host2 = network.GetAttrValue("host");
        string username2 = network.GetAttrValue("username");
        // etc..