Example #1
0
        /// <summary>
        ///     Connects the given server using credentials found in args
        /// </summary>
        /// <param name="context">Application Context</param>
        /// <param name="client">MailService type</param>
        /// <param name="args">Active Event Arguments</param>
        /// <param name="serverType">pop3 or smtp</param>
        public static void ConnectServer(
            ApplicationContext context,
            MailService client,
            Node args,
            string serverType)
        {
            // Retrieving server settings, defaulting to those found in web.config, if not explicitly overridden.
            string server =
                args.GetExChildValue <string> ("server", context) ??
                "localhost";
            int port = args ["port"] != null?
                       args.GetExChildValue <int> ("port", context) :
                           25;

            bool useSsl = args ["ssl"] != null?
                          args.GetExChildValue <bool> ("ssl", context) :
                              false;

            // Connecting client to server
            client.Connect(
                server,
                port,
                useSsl);

            // F**k OATH2!! [quote; its creator!]
            client.AuthenticationMechanisms.Remove("XOAUTH2");

            // Finding username and password to use to authenticate
            string username = null, password = null;

            // Checking if caller supplied username and password, and if so, using those credentials
            if (args ["username"] != null)
            {
                // Notice, this logic allows caller to supply null or empty password, in case specified server does
                // not require authorisation to send emails, in which case, client.Authenticate below will never be invoked!
                username = args.GetExChildValue("username", context, "");
                password = args.GetExChildValue("password", context, "");

                // Authenticating, unless username is empty or null
                if (!string.IsNullOrEmpty(username))
                {
                    client.Authenticate(username, password);
                }
            }
        }
Example #2
0
        /// <summary>
        ///     Connects the given server using credentials found in args
        /// </summary>
        /// <param name="context">Application Context</param>
        /// <param name="client">MailService type</param>
        /// <param name="args">Active Event Arguments</param>
        /// <param name="serverType">pop3 or smtp</param>
        public static void ConnectServer(ApplicationContext context, MailService client, Node args, string serverType)
        {
            // Retrieving server settings, defaulting to those found in web.config, if not explicitly overridden.
            var  server = args.GetExChildValue("server", context, "localhost");
            var  port   = args.GetExChildValue("port", context, 25);
            bool useSsl = args.GetExChildValue("ssl", context, false);

            // Connecting client to server
            client.Connect(
                server,
                port,
                useSsl);

            // F**k OATH2!! [quote; its creator!]
            client.AuthenticationMechanisms.Remove("XOAUTH2");

            // Authenticating user, if credentials were supplied.
            var username = args.GetExChildValue("username", context, "");

            if (!string.IsNullOrEmpty(username))
            {
                client.Authenticate(username, args.GetExChildValue("password", context, ""));
            }
        }
Example #3
0
        /// <summary>
        ///     Connects the given server using credentials found in args
        /// </summary>
        /// <param name="context">Application Context</param>
        /// <param name="client">MailService type</param>
        /// <param name="args">Active Event Arguments</param>
        /// <param name="serverType">pop3 or smtp</param>
        public static void ConnectServer(
            ApplicationContext context,
            MailService client,
            Node args,
            string serverType)
        {
            // Retrieving server settings, defaulting to those found in web.config if not explicitly overridden
            string server =
                args.GetChildValue <string> ("server", context) ??
                context.Raise(
                    ".p5.config.get",
                    new Node("", string.Format("p5.{0}.server", serverType))) [0].Get <string> (context);
            int port = args["port"] != null?
                       args.GetChildValue <int> ("port", context) :
                           context.Raise(
                               ".p5.config.get",
                               new Node("", string.Format("p5.{0}.port", serverType)))[0].Get <int> (context);

            bool useSsl = args["ssl"] != null?
                          args.GetChildValue <bool> ("ssl", context) :
                              context.Raise(
                                  ".p5.config.get",
                                  new Node("", string.Format("p5.{0}.use-ssl", serverType)))[0].Get <bool> (context);

            // Connecting client to server
            client.Connect(
                server,
                port,
                useSsl);

            // F**k OATH2!! [quote; its creator!]
            client.AuthenticationMechanisms.Remove("XOAUTH2");

            // Finding username and password to use to authenticate
            string username = null, password = null;

            // Checking if caller supplied username and password, and if so, using those credentials
            if (args ["username"] != null)
            {
                // Notice, this logic allows caller to supply null or empty password, in case specified server does
                // not require authorisation to send emails, in which case, client.Authenticate below will never be invoked!
                username = args.GetChildValue("username", context, "");
                password = args.GetChildValue("password", context, "");
            }
            else
            {
                // Retrieving default username/password from web.config
                username = context.Raise(
                    ".p5.config.get",
                    new Node("", string.Format("p5.{0}.username", serverType))) [0].Get <string> (context);
                password = context.Raise(
                    ".p5.config.get",
                    new Node("", string.Format(".p5.{0}.password", serverType))) [0].Get <string> (context);
            }

            if (!string.IsNullOrEmpty(username))
            {
                // Authenticating
                client.Authenticate(username, password);
            }
        }