• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# NetworkCredential类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中NetworkCredential的典型用法代码示例。如果您正苦于以下问题:C# NetworkCredential类的具体用法?C# NetworkCredential怎么用?C# NetworkCredential使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



NetworkCredential类属于命名空间,在下文中一共展示了NetworkCredential类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Button1_Click

    protected void Button1_Click(object sender, EventArgs e)
    {
        locator.locate find = new locator.locate();
          String j = bgroup.Text;
         String[] emailList= find.mailing(j);
         // string a = group.Text;
        //   a = a + ", [email protected],[email protected]";

        //List<String> emailList=null;
        //emailList.
           string a="";
           foreach(String eachItem in emailList){
           a = eachItem+", "+a;
           }
           a = a.Substring(0, a.Length - 2);
        string b = body.Text;
        MailMessage MyMailMessage = new MailMessage("[email protected]", a,"Donor Notifications", b);
        MyMailMessage.IsBodyHtml = false;
        NetworkCredential mailAuthentication = new NetworkCredential("[email protected]", "giveblood");
        SmtpClient mailClient = new SmtpClient("smtp.gmail.com", 587);
        mailClient.EnableSsl = true;
        mailClient.UseDefaultCredentials = false;
        mailClient.Credentials = mailAuthentication;
        mailClient.Send(MyMailMessage);
        Label1.Text = "Sent Notifications Successfully";
    }
开发者ID:anoopjavvadi,项目名称:Blood-Donor-Explorer,代码行数:26,代码来源:Sendnotifications.aspx.cs


示例2: ProxyExplicitlyProvided_DefaultCredentials_Ignored

        public void ProxyExplicitlyProvided_DefaultCredentials_Ignored()
        {
            int port;
            Task<LoopbackGetRequestHttpProxy.ProxyResult> proxyTask = LoopbackGetRequestHttpProxy.StartAsync(out port, requireAuth: true, expectCreds: true);
            Uri proxyUrl = new Uri($"http://localhost:{port}");

            var rightCreds = new NetworkCredential("rightusername", "rightpassword");
            var wrongCreds = new NetworkCredential("wrongusername", "wrongpassword");

            using (var handler = new HttpClientHandler())
            using (var client = new HttpClient(handler))
            {
                handler.Proxy = new UseSpecifiedUriWebProxy(proxyUrl, rightCreds);
                handler.DefaultProxyCredentials = wrongCreds;

                Task<HttpResponseMessage> responseTask = client.GetAsync(Configuration.Http.RemoteEchoServer);
                Task<string> responseStringTask = responseTask.ContinueWith(t => t.Result.Content.ReadAsStringAsync(), TaskScheduler.Default).Unwrap();
                Task.WaitAll(proxyTask, responseTask, responseStringTask);

                TestHelper.VerifyResponseBody(responseStringTask.Result, responseTask.Result.Content.Headers.ContentMD5, false, null);
                Assert.Equal(Encoding.ASCII.GetString(proxyTask.Result.ResponseContent), responseStringTask.Result);

                string expectedAuth = $"{rightCreds.UserName}:{rightCreds.Password}";
                Assert.Equal(expectedAuth, proxyTask.Result.AuthenticationHeaderValue);
            }
        }
开发者ID:naamunds,项目名称:corefx,代码行数:26,代码来源:HttpClientHandlerTest.DefaultProxyCredentials.cs


示例3: Ctor_UserNamePasswordDomain_Success

 public static void Ctor_UserNamePasswordDomain_Success()
 {
     NetworkCredential nc = new NetworkCredential("username", "password", "domain");
     Assert.Equal("username", nc.UserName);
     Assert.Equal("password", nc.Password);
     Assert.Equal("domain", nc.Domain);
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:7,代码来源:NetworkCredentialTest.cs


示例4: Button1_Click

    protected void Button1_Click(object sender, EventArgs e)
    {
        MailMessage msg = new MailMessage();
        MailAddress mailadd = new MailAddress("[email protected]","Amita Shukla");
        msg.From = mailadd;
        msg.To.Add(new MailAddress(TextBox1.Text));
        msg.Subject = TextBox2.Text;
        msg.Body = TextBox4.Text;
        if (FileUpload1.HasFile)
        {
            msg.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
        }

        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com";
        NetworkCredential nkc = new NetworkCredential("[email protected]", "*******");
        smtp.Credentials = nkc;
        smtp.EnableSsl = true;

        try
        {
            smtp.Send(msg);
            Label5.Text = "Email sent successfully";
        }
        catch(Exception ex)
        {
            Label5.Text = ex.Message;
        }
    }
开发者ID:amita-shukla,项目名称:email,代码行数:29,代码来源:Default.aspx.cs


示例5: SendMail

    public static bool SendMail(string gMailAccount, string password, string to, string subject, string message)
    {
        try
        {
            NetworkCredential loginInfo = new NetworkCredential(gMailAccount, password);
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress(gMailAccount);
            msg.To.Add(new MailAddress(to));
            msg.Subject = subject;
            msg.Body = message;
            msg.IsBodyHtml = true;
            SmtpClient client = new SmtpClient("smtp.gmail.com");
            client.Port = 587;
            client.EnableSsl = true;
            client.UseDefaultCredentials = false;
            client.Credentials = loginInfo;
            client.Send(msg);

            return true;
        }
        catch (Exception)
        {
            return false;
        }
    }
开发者ID:lordiejake,项目名称:aspDesignTemlpates,代码行数:25,代码来源:MailSender.cs


示例6: EmailNotification

    void EmailNotification()
    {
        MailMessage mm = new MailMessage();
        mm.From = new MailAddress("[email protected]");
        mm.To.Add(txtEmail.Text.ToString());
        mm.Subject = "Feedback - Inquiry/Issue";
        string body = "Hello " + txtFirstName.Text.Trim() + ",";
        body += "<br /><br />Thank you for sending us a message";
        body += "<br /><br />we will get back to you shortly using the email " + txtEmail.Text.ToString();
        body += "<br /><br />Thanks";
        body += "<br /><br />";
        body += "<br /><br />Customer Care - Lifeline Ambulance Rescue Inc.,";
        mm.Body = body;
        mm.IsBodyHtml = true;

        SmtpClient client = new SmtpClient();
        client.EnableSsl = true;
        client.UseDefaultCredentials = true;
        NetworkCredential cred = new NetworkCredential("[email protected]", "swantonbomb");
        client.Host = "smtp.gmail.com";
        client.Port = 587;
        client.DeliveryMethod = SmtpDeliveryMethod.Network;
        client.Credentials = cred;
        client.Send(mm);
    }
开发者ID:thegrassjelly,项目名称:Lifeline-CRM,代码行数:25,代码来源:site.master.cs


示例7: ValidateCreateContext

        internal void ValidateCreateContext(
            string package,
            NetworkCredential credential,
            string servicePrincipalName,
            ExtendedProtectionPolicy policy,
            ProtectionLevel protectionLevel,
            TokenImpersonationLevel impersonationLevel)
        {
            if (policy != null)
            {
                // One of these must be set if EP is turned on
                if (policy.CustomChannelBinding == null && policy.CustomServiceNames == null)
                {
                    throw new ArgumentException(SR.net_auth_must_specify_extended_protection_scheme, nameof(policy));
                }

                _extendedProtectionPolicy = policy;
            }
            else
            {
                _extendedProtectionPolicy = new ExtendedProtectionPolicy(PolicyEnforcement.Never);
            }

            ValidateCreateContext(package, true, credential, servicePrincipalName, _extendedProtectionPolicy.CustomChannelBinding, protectionLevel, impersonationLevel);
        }
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:25,代码来源:NegoState.Windows.cs


示例8: Start

	// Use this for initialization
	void Start () {
		PlaneXML = new PlaneXMLv1 ();
		c = new NetworkCredential("[email protected]", "B8955E7C-C03F-4CF9-9B8D-C38C50FDA67A");
		PlaneXML.Credentials = c;
		flight = PlaneXML.FlightInfo(flightID, true, true);
		StartCoroutine("refresh");
	}
开发者ID:Scub3d,项目名称:Aerohacks,代码行数:8,代码来源:nearMeFetcher.cs


示例9: brnSendEmail_Click

    protected void brnSendEmail_Click(object sender, EventArgs e)
    {
        lblMessage.ForeColor = Color.Green;
        lblMessage.Text = "";

        try
        {
            // initialize exchange client
            NetworkCredential credential = new NetworkCredential(txtUsername.Text, Session["Password"].ToString(), txtDomain.Text);
            Aspose.Email.Exchange.ExchangeClient client = new Aspose.Email.Exchange.ExchangeClient(txtHost.Text, credential);

            // build message
            MailMessage msg = new MailMessage();
            msg.From = txtFrom.Text;
            msg.To = txtTo.Text;
            msg.Subject = txtSubject.Text;
            msg.TextBody = txtTextBody.Text;

            // send email
            client.Send(msg);

            lblMessage.Text = "Successfully sent email using Microsoft Exchange server.<br><hr>";
        }
        catch (Exception ex)
        {
            lblMessage.ForeColor = Color.Red;
            lblMessage.Text = "Error: " + ex.Message;
        }
    }
开发者ID:williamesharp,项目名称:Aspose_Email_NET,代码行数:29,代码来源:Exchange-Send-Email.aspx.cs


示例10: SendMail

    public bool SendMail(ArrayList toAdresses)
    {
        SmtpClient smtpClient = new SmtpClient(adminMailServer, adminMailPort);

        NetworkCredential networkCredential = new NetworkCredential(adminMailAddress, adminMailPassword);

        smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
        smtpClient.EnableSsl = true;
        smtpClient.UseDefaultCredentials = false;
        smtpClient.Credentials = networkCredential;

        MailMessage mail = new MailMessage();

        mail.From = new MailAddress(adminMailAddress, appName);

        for (int i = 0; i < (toAdresses.Count); i++)
        {
            mail.To.Add(new MailAddress(toAdresses[i].ToString()));
        }

        mail.Subject = appName + " - Mail Notification";
        mail.IsBodyHtml = true;
        mail.Body = MessageModifier();
        //mail.Priority = MailPriority.High;

        try
        {
            smtpClient.Send(mail);
            return true;
        }
        catch
        {
            return false;
        }
    }
开发者ID:ravikiranjuluru,项目名称:synergyrms,代码行数:35,代码来源:MailManager.cs


示例11: sendReceipt

    //Now in ppClass_sb.cs
    //get expired permits and reset spots to unoccupied
    //private void _resetSpots()
    //{
    //    //get expired spots
    //    var expiredSpots = objPark.getExpiredPermits(DateTime.Now);
    //    foreach (var spot in expiredSpots)
    //    {
    //       var spotSingle = objPark.getSpotBySpot(spot.spot);
    //    }
    //}
    //Send Email Receiptfd
    protected void sendReceipt(DateTime _timeExp, string _spot)
    {
        //This is the script provided by my hosting to send mail (Source URL: https://support.gearhost.com/KB/a777/aspnet-form-to-email-example.aspx?KBSearchID=41912)
        try
        {
            //Create the msg object to be sent
            MailMessage msg = new MailMessage();
            //Add your email address to the recipients
            msg.To.Add(txt_email.Text);
            //Configure the address we are sending the mail from
            MailAddress address = new MailAddress("[email protected]");
            msg.From = address;
            //Append their name in the beginning of the subject
            msg.Subject = "Your KDH Parking Reciept";
            msg.Body = "Thank you for parking with us. You are parked in " + _spot + " and your permit expires at " + _timeExp.ToString(@"hh\:mm\:ss") + ".";

            //Configure an SmtpClient to send the mail.
            SmtpClient client = new SmtpClient("mail.stevebosworth.ca");
            client.EnableSsl = false; //only enable this if your provider requires it
            //Setup credentials to login to our sender email address ("UserName", "Password")
            NetworkCredential credentials = new NetworkCredential("[email protected]", "Pa55w0rd!");
            client.Credentials = credentials;

            //Send the msg
            client.Send(msg);
        }
        catch
        {
            //If the message failed at some point, let the user know

            lbl_message.Text = "Your message failed to send, please try again.";
        }
    }
开发者ID:stevebosworth,项目名称:Kirkland-District-Hospital,代码行数:45,代码来源:pp_public_sb.aspx.cs


示例12: Submit_Click

    protected void Submit_Click(object sender, EventArgs e)
    {
        MailAddress mailFrom = new MailAddress("[email protected].com");
        MailAddress mailTo = new MailAddress("[email protected]");

        MailMessage emailMessage = new MailMessage(mailFrom, mailTo);

        emailMessage.Subject = "Unsubscribe";
        emailMessage.Body += "<br>Email: " + email.Text;

        emailMessage.IsBodyHtml = false;

        SmtpClient myMail = new SmtpClient();
        myMail.Host = "localhost";
        myMail.DeliveryMethod = SmtpDeliveryMethod.Network;

        //myMail.Port = 25;
        NetworkCredential SMTPUserInfo = new NetworkCredential("[email protected]", "!p3Learning", "pinnacle3learning.com");
        //myMail.UseDefaultCredentials = false;
        myMail.Credentials = SMTPUserInfo;

        myMail.Send(emailMessage);

        MultiView1.ActiveViewIndex = 1;
    }
开发者ID:KungfuCreatives,项目名称:P3WebApp,代码行数:25,代码来源:unsubscribe.aspx.cs


示例13: AuthenticateAsClient

 //
 public virtual void AuthenticateAsClient( NetworkCredential       credential,
                                         string                  targetName,
                                         ProtectionLevel         requiredProtectionLevel,   //this will be the ultimate result or exception
                                         TokenImpersonationLevel allowedImpersonationLevel) //this OR LOWER will be ultimate result in auth context
 {
     AuthenticateAsClient(credential, null, targetName, requiredProtectionLevel, allowedImpersonationLevel);
 }
开发者ID:uQr,项目名称:referencesource,代码行数:8,代码来源:NegotiateStream.cs


示例14: brnSendEmail_Click

    protected void brnSendEmail_Click(object sender, EventArgs e)
    {
        lblMessage.Text = "";
        lblMessage.ForeColor = Color.Green;

        try
        {
            // initialize exchange client
            NetworkCredential credential = new NetworkCredential(txtUsername.Text, txtPassword.Text, txtDomain.Text);
            Aspose.Email.Exchange.ExchangeWebServiceClient client = new Aspose.Email.Exchange.ExchangeWebServiceClient(txtHost.Text, credential);

            // get mailbox and folders information
            Aspose.Email.Exchange.ExchangeMailboxInfo exchangeMailboxInfo = client.GetMailboxInfo();
            lblMailboxURI.Text = exchangeMailboxInfo.MailboxUri;
            lblInboxURI.Text = exchangeMailboxInfo.InboxUri;
            lblSentItemsURI.Text = exchangeMailboxInfo.SentItemsUri;
            lblDraftsURI.Text = exchangeMailboxInfo.DraftsUri;
            lblCalendarURI.Text = exchangeMailboxInfo.CalendarUri;
            lblDeletedItemsURI.Text = exchangeMailboxInfo.DeletedItemsUri;

            lblMessage.Text = "Successfully connected to Microsoft Exchange server.<br><hr>";
        }
        catch (Exception ex)
        {
            lblMessage.ForeColor = Color.Red;
            lblMessage.Text = "Error: " + ex.Message;
        }
    }
开发者ID:williamesharp,项目名称:Aspose_Email_NET,代码行数:28,代码来源:Exchange-Server-Mailbox-Folder-Information-EWS.aspx.cs


示例15: EmailForActivationRegistry

    public string EmailForActivationRegistry(string emailOfUser, MailMessage mail)
    {
        string status = "";

        SmtpClient smtpClient = new SmtpClient();
        smtpClient.Host = "smtp.gmail.com";
        smtpClient.EnableSsl = true;
        smtpClient.Port = 587;
        smtpClient.UseDefaultCredentials = true;
        NetworkCredential networkCred = new NetworkCredential("[email protected]", "ULatina506");
        smtpClient.Credentials = networkCred;

        try
        {
            smtpClient.Send(mail);
            status = "Enviado";
        }
        catch
        {
            status = "No Enviado";

        }

        return status;
    }
开发者ID:SamaraDevelopments,项目名称:SamaraParking,代码行数:25,代码来源:RegistryBusiness.cs


示例16: Submit_Click

    protected void Submit_Click(object sender, EventArgs e)
    {
        MembershipUser membershipuser;
        MailMessage mailmessage;
        NetworkCredential networkcredential;
        SmtpClient smtpclient;

        if (ValidateInput())
        {
            membershipuser = Membership.GetUser(EmailAddress.Text);
            if (membershipuser != null)
            {
                mailmessage = new MailMessage(GlobalVariable.superadministratoremailaddress, EmailAddress.Text, "Email Subject", GlobalVariable.emailheadertemplate + "<p>Email Body</p><p>Reset Password Link : <a href=\"" + Request.Url.GetLeftPart(UriPartial.Authority) + Page.ResolveUrl("~/resetpassword.aspx?operation=resetpassword&username=" + membershipuser.ProviderUserKey.ToString()) + "\">Reset Password</a></p>" + GlobalVariable.emailfootertemplate);
                mailmessage.IsBodyHtml = true;
                networkcredential = new NetworkCredential(GlobalVariable.superadministratoremailaddress, GlobalVariable.superadministratoremailpassword);
                smtpclient = new SmtpClient("smtp.mail.yahoo.com", 587);
                smtpclient.UseDefaultCredentials = false;
                smtpclient.Credentials = networkcredential;
                smtpclient.Send(mailmessage);

                Response.Redirect("resetpassword.aspx?operation=resetpasswordinstruction");
            }
            else
            {
                EmailAddressError.Visible = true;
            }
        }
        else
        {

        }
    }
开发者ID:soosinyi92,项目名称:webshopinholland,代码行数:32,代码来源:requestnewpassword.aspx.cs


示例17: AcquireCredentialsHandle

        internal static unsafe SafeFreeCredentials AcquireCredentialsHandle(string package, bool isServer, NetworkCredential credential)
        {
            SafeSspiAuthDataHandle authData = null;
            try
            {
                Interop.SECURITY_STATUS result = Interop.SspiCli.SspiEncodeStringsAsAuthIdentity(
                    credential.UserName, credential.Domain,
                    credential.Password, out authData);

                if (result != Interop.SECURITY_STATUS.OK)
                {
                    if (NetEventSource.IsEnabled) NetEventSource.Error(null, SR.Format(SR.net_log_operation_failed_with_error, nameof(Interop.SspiCli.SspiEncodeStringsAsAuthIdentity), $"0x{(int)result:X}"));
                    throw new Win32Exception((int)result);
                }

                return SSPIWrapper.AcquireCredentialsHandle(GlobalSSPI.SSPIAuth,
                    package, (isServer ? Interop.SspiCli.CredentialUse.SECPKG_CRED_INBOUND : Interop.SspiCli.CredentialUse.SECPKG_CRED_OUTBOUND), ref authData);
            }
            finally
            {
                if (authData != null)
                {
                    authData.Dispose();
                }
            }
        }
开发者ID:chcosta,项目名称:corefx,代码行数:26,代码来源:NegotiateStreamPal.Windows.cs


示例18: SendMail

    public static bool SendMail(string gMailAccount, string password, string to, string subject, string message)
    {
        try
        {
            NetworkCredential loginInfo = new NetworkCredential("[email protected]", "sivababu86");
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress("[email protected]");
            msg.To.Add(new MailAddress(to));
            msg.Subject = subject;
            msg.Body = message;
            msg.IsBodyHtml = true;

            //if any files are attached used this code..
            //msg.Attachments.Add(new Attachment("D:\\Human.doc"));
            //msg.Attachments.Add(new Attachment("D:\\Music.mp3"));
            //msg.Attachments.Add(new Attachment("D:\\Music.mp3"));

            SmtpClient client = new SmtpClient("smtp.gmail.com");
            client.EnableSsl = true;
            client.UseDefaultCredentials = false;
            client.Credentials = loginInfo;
            client.Send(msg);

            return true;
        }
        catch (Exception)
        {
            return false;
        }
    }
开发者ID:gowrinath,项目名称:Public-Health-Care-System,代码行数:30,代码来源:Gmail.cs


示例19: ListMessages

    private void ListMessages()
    {
        lblMessage.ForeColor = Color.Green;
        lblMessage.Text = "";

        try
        {
            // initialize exchange client
            NetworkCredential credential = new NetworkCredential(txtUsername.Text, Session["Password"].ToString(), txtDomain.Text);
            Aspose.Email.Exchange.ExchangeWebServiceClient client = new Aspose.Email.Exchange.ExchangeWebServiceClient(txtHost.Text, credential);

            // get list of messages
            Aspose.Email.Exchange.ExchangeMailboxInfo exchangeMailboxInfo = client.GetMailboxInfo();
            Aspose.Email.Exchange.ExchangeMessageInfoCollection msgCollection = client.ListMessages(exchangeMailboxInfo.InboxUri);
            gvMessages.DataSource = msgCollection;
            gvMessages.DataBind();

            lblMessage.Text = "Successfully connected to Microsoft Exchange server.<br><hr>";
        }
        catch (Exception ex)
        {
            lblMessage.ForeColor = Color.Red;
            lblMessage.Text = "Error: " + ex.Message;
        }
    }
开发者ID:williamesharp,项目名称:Aspose_Email_NET,代码行数:25,代码来源:Exchange-List-Messages-EWS.aspx.cs


示例20: Send

    public static void Send(string Body,string subject, string Address)
    {
        try
        {

        SmtpClient smtpClient = new SmtpClient();
        NetworkCredential basicCredential = new NetworkCredential("nephromorsys", "Orr190557");
        MailMessage message = new MailMessage();
        MailAddress fromAddress = new MailAddress("[email protected]");

        //smtpClient.Credentials = new NetworkCredential("nephromorsys", "Orr190557");
        smtpClient.Host = "smtp.gmail.com";
        smtpClient.UseDefaultCredentials = false;
        smtpClient.Credentials = basicCredential;
        smtpClient.Port = 587;
        smtpClient.EnableSsl = true;

        message.From = fromAddress;
        message.Subject = subject;
        //Set IsBodyHtml to true means you can send HTML email.
        message.IsBodyHtml = true;
        message.Body = "<h1> " + Body +"</h1>";
        message.To.Add(Address);
        //message.To.Add("[email protected]");
        //message.To.Add("[email protected]");

            smtpClient.Send(message);
        }
        catch (Exception ex)
        {
            //Error, could not send the message
            //Response.Write(ex.Message);
            throw ex;
        }
    }
开发者ID:peless,项目名称:290513,代码行数:35,代码来源:Mailmsg.cs



注:本文中的NetworkCredential类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# NetworkDisconnection类代码示例发布时间:2022-05-24
下一篇:
C# NetworkConnectionError类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap