def connect_to_Server2(serverName, username): piServers = PIServers() #piServers = PISystems() global piServer netcred = NetworkCredential(username,username,None) piServer = piServers[serverName] piServer.Connect(netcred, PIAuthenticationMode.WindowsAuthentication)
def connect_to_Server(serverName, username): piServers = PIServers() #piServers = PISystems() global piServer netcred = NetworkCredential(username,None) piServer = piServers[serverName] piServer.Connect(netcred)
def get_server(server_name, login=None): """Connect to server""" PI_server = AF.PI.PIServers()[server_name] if login is not None: PI_server.Connect(NetworkCredential(*login), AF.PI.PIAuthenticationMode.PIUserAuthentication) return PI_server
def sendNote(self, sendTo, replyToAdr, headertext, bodyText, lnkAdr): try: smtpServer = WebConfigurationManager.AppSettings['smtpServer'] smtpUser = WebConfigurationManager.AppSettings['smtpUser'] smtpPwd = WebConfigurationManager.AppSettings['smtpPwd'] fromAddr = WebConfigurationManager.AppSettings['cptchSndrAdrss'] # load the template for the HTML-mail tmpltPath = self.Page.Server.MapPath( WebConfigurationManager.AppSettings['JobTrialHtmlBody']) self.log.w2lgDvlp('ItemJobMsg->sendNote = ' + tmpltPath) file = open(tmpltPath) mailBody = file.read() file.close() #Create A New SmtpClient Object mailClient = SmtpClient(smtpServer, 25) mailClient.EnableSsl = True mailCred = NetworkCredential() mailCred.UserName = smtpUser mailCred.Password = smtpPwd mailClient.Credentials = mailCred msg = MailMessage() msg.From = MailAddress(fromAddr) msg.ReplyTo = MailAddress(replyToAdr) msg.To.Add(MailAddress(sendTo)) msg.SubjectEncoding = System.Text.Encoding.UTF8 msg.BodyEncoding = System.Text.Encoding.UTF8 msg.IsBodyHtml = True mailSubj = self.ui.getCtrl('msg_mailSubject').Text + headertext mailBody = mailBody.replace('###header###', headertext) mailBody = mailBody.replace('###body###', bodyText) mailBody = mailBody.replace('###link###', lnkAdr) self.log.w2lgDvlp('ItemJobMsg.sendNote link-address : ' + lnkAdr) msg.Subject = mailSubj msg.Body = mailBody mailClient.Send(msg) except Exception, e: self.log.w2lgError(traceback.format_exc())
def sendNote( self, sendTo, replyToAdr, headertext, bodyText, lnkAdr ): try: smtpServer = WebConfigurationManager.AppSettings['smtpServer'] smtpUser = WebConfigurationManager.AppSettings['smtpUser'] smtpPwd = WebConfigurationManager.AppSettings['smtpPwd'] fromAddr = WebConfigurationManager.AppSettings['cptchSndrAdrss'] # load the template for the HTML-mail tmpltPath = self.Page.Server.MapPath( WebConfigurationManager.AppSettings['JobTrialHtmlBody'] ) self.log.w2lgDvlp('ItemJobMsg->sendNote = ' + tmpltPath ) file = open(tmpltPath) mailBody = file.read() file.close() #Create A New SmtpClient Object mailClient = SmtpClient(smtpServer,25) mailClient.EnableSsl = True mailCred = NetworkCredential() mailCred.UserName = smtpUser mailCred.Password = smtpPwd mailClient.Credentials = mailCred msg = MailMessage() msg.From = MailAddress(fromAddr) msg.ReplyTo = MailAddress(replyToAdr) msg.To.Add( MailAddress( sendTo ) ) msg.SubjectEncoding = System.Text.Encoding.UTF8 msg.BodyEncoding = System.Text.Encoding.UTF8 msg.IsBodyHtml = True mailSubj = self.ui.getCtrl('msg_mailSubject').Text + headertext mailBody = mailBody.replace('###header###' , headertext ) mailBody = mailBody.replace('###body###' , bodyText ) mailBody = mailBody.replace('###link###' , lnkAdr ) self.log.w2lgDvlp('ItemJobMsg.sendNote link-address : ' + lnkAdr ) msg.Subject = mailSubj msg.Body = mailBody mailClient.Send(msg) except Exception,e: self.log.w2lgError(traceback.format_exc())
def update(): global username, password request = WebRequest.Create("https://mail.google.com/mail/feed/atom") request.Credentials = NetworkCredential(username, password) entryList = List[Entry]() def onUpdate(): if NetworkInterface.GetIsNetworkAvailable(): try: response = None stream = None try: response = request.GetResponse() stream = response.GetResponseStream() doc = XmlDocument() doc.Load(stream) for entryXmlNode in doc.GetElementsByTagName("entry"): entry = Entry() for xmlNode in entryXmlNode.ChildNodes: if xmlNode.Name.Equals("title"): entry.Title = xmlNode.InnerText elif xmlNode.Name.Equals("issued"): entry.Created = DateTime.Parse( xmlNode.InnerText) elif xmlNode.Name.Equals("modified"): entry.Modified = DateTime.Parse( xmlNode.InnerText) elif xmlNode.Name.Equals("link"): for attribute in xmlNode.Attributes: if attribute.Name.Equals("href"): entry.Resource = Uri(attribute.Value) elif xmlNode.Name.Equals("author"): for childXmlNode in xmlNode.ChildNodes: if childXmlNode.Name.Equals("name"): entry.Author = childXmlNode.InnerText entry.Image = Uri( "http://www.google.co.jp/options/icons/gmail.gif") entryList.Add(entry) finally: if stream is not None: stream.Close() if response is not None: response.Close() except Exception, e: Trace.WriteLine(e.clsException.Message) Trace.WriteLine(e.clsException.StackTrace)
def sendToNejobaTeam(): try: # get the textdata for mail tool.ui.getCtrlTree( Page.Master ) mailSubj = tool.ui.getCtrl('txbHeader').Text mailBody = tool.ui.getCtrl('txtMain').Text smtpServer = WebConfigurationManager.AppSettings['smtpServer'] smtpUser = WebConfigurationManager.AppSettings['smtpUser'] smtpPwd = WebConfigurationManager.AppSettings['smtpPwd'] fromAddr = WebConfigurationManager.AppSettings['cptchSndrAdrss'] #Create A New SmtpClient Object mailClient = SmtpClient(smtpServer,25) mailClient.EnableSsl = True mailCred = NetworkCredential() mailCred.UserName = smtpUser mailCred.Password = smtpPwd mailClient.Credentials = mailCred sendTo = '*****@*****.**' msg = MailMessage() msg.From = MailAddress('*****@*****.**') msg.ReplyTo = MailAddress('*****@*****.**') msg.To.Add( MailAddress( sendTo ) ) msg.SubjectEncoding = System.Text.Encoding.UTF8 msg.BodyEncoding = System.Text.Encoding.UTF8 msg.IsBodyHtml = False msg.Subject = mailSubj msg.Body = mailBody mailClient.Send(msg) # toogle divs to show message was send tool.ui.getCtrl('mailSendSuccesfullyMessage').Visible = True tool.ui.getCtrl('divEditArea').Visible = False except Exception,e: tool.log.w2lgError(traceback.format_exc())
def sendToNejobaTeam(): try: # get the textdata for mail tool.ui.getCtrlTree(Page.Master) mailSubj = tool.ui.getCtrl('txbHeader').Text mailBody = tool.ui.getCtrl('txtMain').Text smtpServer = WebConfigurationManager.AppSettings['smtpServer'] smtpUser = WebConfigurationManager.AppSettings['smtpUser'] smtpPwd = WebConfigurationManager.AppSettings['smtpPwd'] fromAddr = WebConfigurationManager.AppSettings['cptchSndrAdrss'] #Create A New SmtpClient Object mailClient = SmtpClient(smtpServer, 25) mailClient.EnableSsl = True mailCred = NetworkCredential() mailCred.UserName = smtpUser mailCred.Password = smtpPwd mailClient.Credentials = mailCred sendTo = '*****@*****.**' msg = MailMessage() msg.From = MailAddress('*****@*****.**') msg.ReplyTo = MailAddress('*****@*****.**') msg.To.Add(MailAddress(sendTo)) msg.SubjectEncoding = System.Text.Encoding.UTF8 msg.BodyEncoding = System.Text.Encoding.UTF8 msg.IsBodyHtml = False msg.Subject = mailSubj msg.Body = mailBody mailClient.Send(msg) # toogle divs to show message was send tool.ui.getCtrl('mailSendSuccesfullyMessage').Visible = True tool.ui.getCtrl('divEditArea').Visible = False except Exception, e: tool.log.w2lgError(traceback.format_exc())
def __init__( self, server=None, username=None, password=None, domain=None, authentication_mode=AuthenticationMode.PI_USER_AUTHENTICATION, timeout=None, ): if server and server not in self.servers: message = 'Server "{server}" not found, using the default server.' warn(message=message.format(server=server), category=UserWarning) if bool(username) != bool(password): raise ValueError( "When passing credentials both the username and password must be specified." ) if domain and not username: raise ValueError( "A domain can only specified together with a username and password." ) if username: from System.Net import NetworkCredential from System.Security import SecureString secure_pass = SecureString() for c in password: secure_pass.AppendChar(c) cred = [username, secure_pass] + ([domain] if domain else []) self._credentials = (NetworkCredential(*cred), int(authentication_mode)) else: self._credentials = None self.connection = self.servers.get(server, self.default_server) if timeout: from System import TimeSpan # System.TimeSpan(hours, minutes, seconds) self.connection.ConnectionInfo.OperationTimeOut = TimeSpan(0, 0, timeout)
# -*- encoding: utf-8 -*- from System import Uri from System.Net import CredentialCache, NetworkCredential from System.Reflection import FieldInfo, BindingFlags prefix = "http://msrprx.appspot.com" path = "/api" def _get(instance, name): type = instance.GetType() field = type.GetField(name, BindingFlags.Instance | BindingFlags.NonPublic) return field.GetValue(instance) def _set(instance, name, value): type = instance.GetType() field = type.GetField(name, BindingFlags.Instance | BindingFlags.NonPublic) field.SetValue(instance, value) username = CurrentSession.Connections[0].UserInfo.UserName password = CurrentSession.Connections[0].UserInfo.Password credential = _get(CurrentSession.TwitterService, "_credential") credential.Remove(Uri(prefix), "Basic") credential.Add(Uri(prefix), "Basic", NetworkCredential(username, password)) _set(CurrentSession.TwitterService, "_credential", credential) CurrentSession.TwitterService.ServiceServerPrefix = prefix + path