c# - Ask for credentials in email application -
i need make application in visual studio retrieve inbox, sent messages , attachments exchange email account, being able mark read , delete said messages (an outlook-like application if will).
i have code retrieve inbox , attachments outlook, need separate outlook or @ least need able ask credentials before shows me messages. code have:
outlook.application application = new outlook.application(); outlook.namespace outlooknamespace = application.getnamespace("mapi"); outlook.mapifolder inbox = outlooknamespace.getdefaultfolder(outlook.oldefaultfolders.olfolderinbox); items = inbox.items; //fills listbox inbox messages public void fillinboxlistbox() { (int = 1; <= inbox.items.count; i++) { //lsbxmessages listbox control lsbxmessages.items.add(((outlook.mailitem)inbox.items[i]).subject); } } //when item on listbox selected, loads mail on separate rich text box private void lsbxmessages_selectedindexchanged(object sender, eventargs e) { //lblsubject label put subject of message lblsubject.text = ((outlook.mailitem)inbox.items[(lsbxmessages.selectedindex + 1)]).subject; //lblsender put sender name , email adress lblsender.text = ((outlook.mailitem)inbox.items[(lsbxmessages.selectedindex + 1)]).sendername + " <" + ((outlook.mailitem)inbox.items[(lsbxmessages.selectedindex + 1)]).senderemailaddress + ">"; //i put body of email in richtextbox rtbbody.text = ((outlook.mailitem)inbox.items[(lsbxmessages.selectedindex + 1)]).body; //lbldatesent shows date message sent lbldatesent.text = ((outlook.mailitem)inbox.items[(lsbxmessages.selectedindex + 1)]).senton.tostring(); //rtbreceiver rich text box show adresses email sent rtbreceiver.text = ((outlook.mailitem)inbox.items[(lsbxmessages.selectedindex + 1)]).to; }
any idea on how ask username , password?
you can ask through dialog box want design, have pass parameters outlook through namespace.logon
method. default opening current users default profile.
here tutorial (although shows logging onto default profile without asking username, trivial add own dialog username/password):
https://msdn.microsoft.com/en-us/library/office/ff462097.aspx
its important note can't create instance of outlook if outlook running, you'll have instance of running application. (well, can create "instance" not create new process , use existing process , loaded profile). don't think can load more 1 profile @ time.
Comments
Post a Comment