Exemplo n.º 1
0
        /// <summary>
        /// Sets the Credentials property with the username and password.
        /// </summary>
        /// <param name="request">The object that makes a request to a Uniform Resource Identifier (URI).</param>
        /// <param name="username">The login username.</param>
        /// <param name="password">The login password.</param>
        /// <exception cref="ArgumentNullException">request is null.</exception>
        public static void SetNetworkCredentials(this IWebRequest request, string username, string password)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request", "Argument 'Request' cannot be null.");
            }

            NetworkCredential credentials = NetworkCredentialFactory.Create(username, password);

            if (credentials != null)
            {
                request.Credentials = credentials;
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Sends an e-mail message
 /// </summary>
 public static void SendEmail(bool enableSsl, string messageFrom, string messageTo, string messageSubject,
                              string messageBody, string smtpHost, int smtpPort, string smtpHostUsername,
                              string smtpHostPassword)
 {
     using (var message = new MailMessage(messageFrom, messageTo, messageSubject, messageBody))
     {
         var client = new SmtpClient(smtpHost, smtpPort)
         {
             Credentials = NetworkCredentialFactory.Create(smtpHostUsername, smtpHostPassword),
             EnableSsl   = enableSsl
         };
         client.Send(message);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Gets a WebProxy object based on preference settings.
        /// </summary>
        public static IWebProxy GetWebProxy(this IPreferenceSet prefs)
        {
            if (prefs == null || !prefs.Get <bool>(Preference.UseProxy))
            {
                return(null);
            }

            IWebProxy proxy = new WebProxy(prefs.Get <string>(Preference.ProxyServer),
                                           prefs.Get <int>(Preference.ProxyPort));

            if (prefs.Get <bool>(Preference.UseProxyAuth))
            {
                proxy.Credentials = NetworkCredentialFactory.Create(prefs.Get <string>(Preference.ProxyUser),
                                                                    prefs.Get <string>(Preference.ProxyPass));
            }
            return(proxy);
        }