本文整理汇总了C#中System.Net.NetworkCredential类的典型用法代码示例。如果您正苦于以下问题:C# System.Net.NetworkCredential类的具体用法?C# System.Net.NetworkCredential怎么用?C# System.Net.NetworkCredential使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
System.Net.NetworkCredential类属于命名空间,在下文中一共展示了System.Net.NetworkCredential类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: fileComplaint
internal bool fileComplaint(string name, string pid, string msg)
{
MailMessage message = new MailMessage();
try
{
string emailid = "[email protected]";
string smsg1 = "<b>Purchase Id: </b>" + pid;
string smsg2 = "<br><b>Name: </b>" + name;
string smsg3 = "<br><b>Message: </b>" + msg;
message.To.Add(new MailAddress(emailid));
message.From = new MailAddress("[email protected]");
message.Subject = "Complaint agianst Purchase Id = " + pid;
message.Body = smsg1 + smsg2 + smsg3;
message.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.Port = 25; // Gmail works on this port 587
client.Host = "smtp.net4india.com";
System.Net.NetworkCredential nc = new System.Net.NetworkCredential("[email protected]", "nrmr#ps24");
client.EnableSsl = false;
client.UseDefaultCredentials = false;
client.Credentials = nc;
client.Send(message);
return true;
}
catch (Exception ex)
{
return false;
throw ex;
}
}
示例2: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (Request.ServerVariables["REQUEST_METHOD"] == "POST")
{
strPost = CCLib.Common.Strings.GetFormString("post");
if (strPost == "1" && Session["RegionAdminInfo"] != null)
{
DataRow drAdminInfo = (DataRow)Session["RegionAdminInfo"];
//CCLib.Common.DataAccess.ExecuteDb("update RRS_Login_View set Agreement=1 where RegionId='" + drAdminInfo["RegionId"].ToString().Replace("'", "''") + "' and Password='" + drAdminInfo["Password"].ToString().Replace("'", "''") + "'");
//
this.strPassword = drAdminInfo["Password"].ToString().Replace("'", "''");
this.strRegionID = drAdminInfo["RegionId"].ToString();
this.strConnectionStringToSLX = WebConfigurationManager.AppSettings["strConSLX"];
this.strConnectionStringToCC = WebConfigurationManager.AppSettings["strConLocal"];
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3;
System.Net.ServicePointManager.CertificatePolicy = new CareerCruisingWeb.CCLib.SLXIntegration.TrustAllCertificatePolicy();
this.wsSLXIntegration = new WSCCIntegrationWithSLX.IntegrationWithSLX();
this.userCredential = new System.Net.NetworkCredential("WSCCTOSLX", "Next_20");
this.wsSLXIntegration.Credentials = userCredential;
this.wsSLXIntegration.PreAuthenticate = true;
this.cnnCC = new SqlConnection(this.strConnectionStringToCC);
if (this.cnnCC.State == ConnectionState.Closed)
{
this.cnnCC.Open();
}
this.trsCC = this.cnnCC.BeginTransaction();
this.objDistrictUserID = SqlHelper.ExecuteScalar(this.trsCC, CommandType.Text, this.GetCCSQLSelectDistrictUserID(this.strPassword, this.strRegionID));
this.strDistrictUserID = this.objDistrictUserID != null ? this.objDistrictUserID.ToString() : null;
this.intReturnValue1 = CareerCruisingWeb.CCLib.SLXIntegration.IntegrationWithSLX.ExecuteNoQuery(this.GetCCSQLUpdateRRSUsers(this.strDistrictUserID), this.cnnCC, this.trsCC);
if (this.intReturnValue1 > 0)
{
this.intReturnValue2 = this.wsSLXIntegration.ExecuteNoQuery(this.GetSLXSQLUpdateConRRSUsers(this.strDistrictUserID), this.strConnectionStringToSLX);
if (this.intReturnValue2 > 0)
{
this.trsCC.Commit();
this.ReleaseObjects();
}
else
{
this.trsCC.Rollback();
this.ReleaseObjects();
}
}
else
{
this.trsCC.Rollback();
this.ReleaseObjects();
}
//
Response.Redirect("https://" + ConfigurationManager.AppSettings["strServerName"] + "/Region/Home.aspx");
}
}
}
示例3: SendAnEmail
public void SendAnEmail()
{
try
{
MailMessage _message = new MailMessage();
SmtpClient _smptClient = new SmtpClient();
_message.Subject = _emailSubject;
_message.Body = _emailBody;
MailAddress _mailFrom = new MailAddress(_emailFrom,_emailFromFriendlyName);
MailAddressCollection _mailTo = new MailAddressCollection();
_mailTo.Add(_emailTo);
_message.From = _mailFrom;
_message.To.Add(new MailAddress(_emailTo,_emailToFriendlyName));
System.Net.NetworkCredential _crens = new System.Net.NetworkCredential(
_smtpHostUserName,_smtpHostPassword);
_smptClient.Host = _smtpHost;
_smptClient.Credentials = _crens;
_smptClient.Send(_message);
}
catch (Exception er)
{
Log("C:\\temp\\", "Error.log", er.ToString());
}
}
示例4: FTP
public FTP(string url, Dictionary<string, string> options)
{
//This can be made better by keeping a single ftp stream open,
//unfortunately the .Net model does not allow this as the request is
//bound to a single url (path+file).
//
//To fix this, a thirdparty FTP library is required,
//this would also allow a fix for the FTP servers
//that only support SSL during authentication, not during transfers
//
//If you have experience with a stable open source .Net FTP library,
//please let the Duplicati authors know
Uri u = new Uri(url);
if (!string.IsNullOrEmpty(u.UserInfo))
{
m_userInfo = new System.Net.NetworkCredential();
if (u.UserInfo.IndexOf(":") >= 0)
{
m_userInfo.UserName = u.UserInfo.Substring(0, u.UserInfo.IndexOf(":"));
m_userInfo.Password = u.UserInfo.Substring(u.UserInfo.IndexOf(":") + 1);
}
else
{
m_userInfo.UserName = u.UserInfo;
if (options.ContainsKey("ftp-password"))
m_userInfo.Password = options["ftp-password"];
}
}
else
{
if (options.ContainsKey("ftp-username"))
{
m_userInfo = new System.Net.NetworkCredential();
m_userInfo.UserName = options["ftp-username"];
if (options.ContainsKey("ftp-password"))
m_userInfo.Password = options["ftp-password"];
}
}
m_url = url;
if (!m_url.EndsWith("/"))
m_url += "/";
m_useSSL = Utility.Utility.ParseBoolOption(options, "use-ssl");
m_listVerify = !Utility.Utility.ParseBoolOption(options, "disable-upload-verify");
if (Utility.Utility.ParseBoolOption(options, "ftp-passive"))
{
m_defaultPassive = false;
m_passive = true;
}
if (Utility.Utility.ParseBoolOption(options, "ftp-regular"))
{
m_defaultPassive = false;
m_passive = false;
}
}
示例5: SendEmail
public static int SendEmail(string ToEmail, string fromEmail, string Subject, string Body, string SMTP, string Username, string Password)
{
try
{
MailMessage mailMessage = new MailMessage(new MailAddress(fromEmail), new MailAddress(ToEmail));
System.Net.NetworkCredential SmtpUser = new System.Net.NetworkCredential(Username, Password);
dynamic emailHeader = default(StringBuilder);
StringBuilder emailFooter = new StringBuilder();
//message body and subject property
mailMessage.Subject = Subject;
mailMessage.Body = emailHeader.ToString() + Body + emailFooter.ToString();
mailMessage.IsBodyHtml = true;
//create smtp client
SmtpClient smtpMail = new SmtpClient();
//assign smtp properties
smtpMail.Host = SMTP;
smtpMail.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpMail.UseDefaultCredentials = false;
smtpMail.Credentials = SmtpUser;
//send mail
smtpMail.Send(mailMessage);
return 1;
}
catch (Exception ex)
{
DALUtility.ErrorLog(ex.Message, "SendEmail");
return 0;
}
}
示例6: SendNotification
public static void SendNotification(string message, string[] to)
{
SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.Host = "smtp.gmail.com";
client.Port = 587;
// setup Smtp authentication
System.Net.NetworkCredential credentials =
new System.Net.NetworkCredential(SystemMail, SystemMailPass);
client.UseDefaultCredentials = false;
client.Credentials = credentials;
MailMessage msg = new MailMessage();
msg.From = new MailAddress(SystemMail);
foreach (var recipient in to)
{
msg.To.Add(new MailAddress(recipient));
}
msg.Subject = "Автоматическя система оповещений VoTak";
msg.IsBodyHtml = true;
msg.Body = string.Format("<html><head></head><body>{0}</body>", message);
client.Send(msg);
}
示例7: ParseUserInfo
public static System.Net.NetworkCredential ParseUserInfo(System.Uri uri)
{
if (uri == null || string.IsNullOrWhiteSpace(uri.UserInfo)) return null;
System.Net.NetworkCredential result = null;
//Split into tokens taking only 3 tokens max
string[] parts = uri.UserInfo.Split(CredentialSplit, 3);
//cache the length of the split
int partsLength = parts.Length;
//If there are atleast two tokens
if (partsLength > 1)
{
//If there is a domain use it
if (partsLength > 2)
{
result = new System.Net.NetworkCredential(parts[0], parts[2], parts[1]);
}
else //Use the username and password. (optionally use the host as the domain)
{
result = new System.Net.NetworkCredential(parts[0], parts[1]);//, uri.Host);
}
}//There was only one token?
return result;
}
示例8: btnSend_Click
private void btnSend_Click(object sender, EventArgs e)
{
string filename = Path.GetDirectoryName(Application.ExecutablePath);
filename += "\\BugReport.txt";
if (!File.Exists(filename)) return;
if (!IsEmail(txtEmail.Text)) { MessageBox.Show("Use your email!", "Please..."); txtEmail.Focus(); return; }
foreach (Control c in Controls) c.Enabled = false;
//Meglio farlo con un thread separato
System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
mailClient.EnableSsl = true;
System.Net.NetworkCredential cred = new System.Net.NetworkCredential(
"username",
"password");
mailClient.Credentials = cred;
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(txtEmail.Text, "[email protected]", AboutForm.Singleton.GetSoftwareKey(), "Email:" + txtEmail.Text + Environment.NewLine + "Note:" + Environment.NewLine + txtNote.Text);
message.Attachments.Add(new System.Net.Mail.Attachment(filename));
//mailClient.Send(message);
Close();
}
示例9: SendEmail
public static void SendEmail(string toAddress, string subject, string message)
{
string host = ConfigurationManager.AppSettings["EmailServerHost"];
int port = Convert.ToInt32(ConfigurationManager.AppSettings["EmailServerPort"]);
string domain = ConfigurationManager.AppSettings["EmailServerDomain"];
string username = ConfigurationManager.AppSettings["EmailServerUsername"];
string password = ConfigurationManager.AppSettings["EmailServerPassword"];
string fromEmailAddress = ConfigurationManager.AppSettings["EmailFromAddress"];
MailMessage mailMessage = new MailMessage(fromEmailAddress, toAddress);
mailMessage.Subject = subject;
//string queryString = "apkey=" + Convert.ToString(2);
mailMessage.Body = message;
mailMessage.IsBodyHtml = false;
System.Net.NetworkCredential networkCredential = new System.Net.NetworkCredential(username, password, domain);
SmtpClient smtpClient = new SmtpClient();
smtpClient.Host = host;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.Port = port;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = networkCredential;
smtpClient.Send(mailMessage);
}
示例10: send_mail_gmail
public static bool send_mail_gmail(string gmail_sender_account, string gmail_sender_pass, string sender_name, string sender_email, string receiver_name, string receiver_email, string subject, string body_content)
{
bool flag = false;
System.Net.NetworkCredential smtp_user_info = new System.Net.NetworkCredential(gmail_sender_account, gmail_sender_pass);
System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage();
mailMessage.From = new System.Net.Mail.MailAddress(sender_email, sender_name, System.Text.UTF8Encoding.UTF8);
mailMessage.To.Add(new System.Net.Mail.MailAddress(receiver_email, receiver_name.Trim(), System.Text.UTF8Encoding.UTF8));
mailMessage.Subject = subject;
mailMessage.SubjectEncoding = System.Text.Encoding.UTF8;
mailMessage.Body = body_content;
mailMessage.IsBodyHtml = true;
mailMessage.BodyEncoding = System.Text.UnicodeEncoding.UTF8;
//mailMessage.Priority = MailPriority.High;
/* Set the SMTP server and send the email - SMTP gmail ="smtp.gmail.com" port=587*/
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587; //port=25
smtp.Timeout = 100;
smtp.EnableSsl = true;
smtp.Credentials = smtp_user_info;
try
{
smtp.Send(mailMessage);
flag = true;
}
catch (Exception ex)
{
ex.ToString();
}
return flag;
}
示例11: PopulateProjectNameComboBox
private void PopulateProjectNameComboBox()
{
string url = tfsAddressTextBox.Text;
string username = tfsUsernameTextBox.Text;
string password = tfsPasswordTextBox.Text;
Uri tfsUri;
if (!Uri.TryCreate(url, UriKind.Absolute, out tfsUri))
return;
var credentials = new System.Net.NetworkCredential();
if (!string.IsNullOrEmpty(username))
{
credentials.UserName = username;
credentials.Password = password;
}
var tfs = new TfsTeamProjectCollection(tfsUri, credentials);
tfs.Authenticate();
var workItemStore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
projectComboBox.Items.Clear();
foreach (Project project in workItemStore.Projects)
projectComboBox.Items.Add(project.Name);
int existingProjectIndex = -1;
if (!string.IsNullOrEmpty(options.ProjectName))
existingProjectIndex = projectComboBox.Items.IndexOf(options.ProjectName);
projectComboBox.SelectedIndex = existingProjectIndex > 0 ? existingProjectIndex : 0;
}
示例12: Send
public static bool Send(MailObject mailObject)
{
bool result = false;
try
{
MailMessage newMail = new MailMessage();
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
newMail.Subject = mailObject.Receiver.Subject;
newMail.Body = mailObject.Receiver.Body;
newMail.From = new MailAddress(mailObject.MailAddress);
foreach (var item in mailObject.Receiver.MailAddress.Split(','))
newMail.To.Add(item);
newMail.IsBodyHtml = mailObject.IsBodyHtml;
client.Host = mailObject.HostName;
System.Net.NetworkCredential basicauthenticationinfo = new System.Net.NetworkCredential(mailObject.MailAddress, mailObject.MailPassword);
client.Port = mailObject.PortNumber;
client.EnableSsl = mailObject.EnableSsl;
client.UseDefaultCredentials = mailObject.UseDefaultCredentials;
client.Credentials = basicauthenticationinfo;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Send(newMail);
result = true;
}
catch (Exception)
{
result = false;
}
return result;
}
示例13: SendMail
public bool SendMail(string target, string content, int id)
{
try
{
MailMessage mailMsg = new MailMessage();
// To
mailMsg.To.Add(new MailAddress(target));
// From
mailMsg.From = new MailAddress("[email protected]", "Realpoll");
// Subject and multipart/alternative Body
mailMsg.Subject = string.Format("Question details for question #{0}", id);
mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(content, null, MediaTypeNames.Text.Html));
// Init SmtpClient and send
SmtpClient smtpClient = new SmtpClient("smtp.sendgrid.net", Convert.ToInt32(587));
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(WebConfigurationManager.AppSettings["sendgrid:username"], WebConfigurationManager.AppSettings["sendgrid:password"]);
smtpClient.Credentials = credentials;
smtpClient.Send(mailMsg);
return true;
}
catch
{
//TODO: Log
return false;
}
}
示例14: SendMail
public bool SendMail(string from, string to, string replyto, string subject, string body)
{
MailMessage msg = new MailMessage(from, to);
msg.Subject = subject;
msg.Body = body;
msg.BodyEncoding = Encoding.UTF8;
msg.IsBodyHtml = true;
msg.ReplyToList.Add(replyto);
//get config params
string sMTPServerName = WebConfigurationManager.AppSettings["SMTPServerName"].ToString();
string sMTPLoginName = WebConfigurationManager.AppSettings["SMTPLoginName"].ToString();
string sMTPPassword = WebConfigurationManager.AppSettings["SMTPPassword"].ToString();
int sMTPPort = Convert.ToInt32(WebConfigurationManager.AppSettings["SMTPPort"].ToString());
SmtpClient client = new SmtpClient(sMTPServerName, sMTPPort);
System.Net.NetworkCredential basicCredential = new System.Net.NetworkCredential(sMTPLoginName, sMTPPassword);
client.EnableSsl = true;
client.UseDefaultCredentials = true;
client.Credentials = basicCredential;
try
{
client.Send(msg);
}
catch (Exception)
{
return false;
}
return true;
}
示例15: GetSiteManagerClient
private SiteManager.SiteManagerClient GetSiteManagerClient()
{
BasicHttpBinding binding = new BasicHttpBinding();
if (txtWebApplicationUrl.Text.ToLower().Contains("https://"))
{
binding.Security.Mode = BasicHttpSecurityMode.Transport;
}
else
{
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
}
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
EndpointAddress endPoint = new EndpointAddress(txtWebApplicationUrl.Text + "/_vti_bin/provisioning.services.sitemanager/sitemanager.svc");
//Set time outs
binding.ReceiveTimeout = TimeSpan.FromMinutes(15);
binding.CloseTimeout = TimeSpan.FromMinutes(15);
binding.OpenTimeout = TimeSpan.FromMinutes(15);
binding.SendTimeout = TimeSpan.FromMinutes(15);
//Create proxy instance
SiteManager.SiteManagerClient managerClient = new SiteManager.SiteManagerClient(binding, endPoint);
managerClient.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
var impersonator = new System.Net.NetworkCredential(txtAccount.Text, txtPassword.Text, txtDomain.Text);
managerClient.ClientCredentials.Windows.ClientCredential = impersonator;
return managerClient;
}