|
I am trying to send an email from a Vb.code and the following outlook security warning pops up:
"A program is trying to address emial address....."
How could I overide this security message!!
Thanks,
Aman
|
|
|
|
|
|
I would suggest to use SMTP Client instead of outlook component to send an email using an application
SmptClient is an inbuilt .net class , following is an example of using smptClient to send a email.
Dim smtpClient As New Net.Mail.SmtpClient()
Dim mail As New Net.Mail.MailMessage()
'create the message to be sent
mail.To.Add("test@test.com") ' Enter the Email of the person you want to send the mail to
mail.From = New Net.Mail.MailAddress("username@gmail.com", "Your Display Name") ' Enter Your email address
mail.Subject = "Test Message"
mail.Body = "This is a test message"
' Prepare the client to send the above message
'Attach the file as attachment
mail.Attachments.Add(new System.Net.Mail.Attachment("yourFileName.xls"))
smtpClient.Host = "smtp.gmail.com"
smtpClient.EnableSsl = True
smtpClient.Port = 587
smtpClient.Credentials = New Net.NetworkCredential("username@gmail.com", "password") 'Enter username and password of the account , you want to use to send mail
smtpClient.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
smtpClient.Send(mail)
There was a similar question posted
http://www.codeproject.com/script/Forums/View.aspx?fid=1646&msg=2899587[^]
Hope the information is helpful
-Regards
Bharat Jain
bharat.jain.nagpur@gmail.com
|
|
|
|
|
Hi Everybody,
bit of a strange one here, I am not very good with networing tools in .net but are looking at building a firewall i can write and then install on a windows xp/server, i want to setup internet connection sharing on that box with dhcp or my own dhcp server and then issue ip addresses to other machines on the network, any one of the client computers will then try and access the intenet or email, it must then ask them for a username and password i have setup in an admin portals somewhere, it must then log all the bandwidth used by that user and then when they leave i can view a total bandwidth used report for that user on all ports.
If anybody know what assemblies in the .net framework wil help let me know otherwise any other suggestions will be greatly appreciated
I think somekind of a dns interseptor would work but dont know how to handle traffic routing in .net.
|
|
|
|
|
This is the level of what you are trying to do
this is your project
______________
this is your head
Clearly, you are in way over your head.
modified on Thursday, February 5, 2009 1:47 PM
|
|
|
|
|
What you're describing is a proxy server, not a firewall.
There are various proxy protocols you have to implement in your server, plus a rather deep knowledge of TCP/IP and Sockets would be required to pull this off. Forget the Internet Connection SHaring and DHCP Server stuff. They have nothing to do with the ultimate goal of the project (as you described it anyway). Leave the DHCP stuff to an off-the-shelf implementation. One even comes with Windows Server.
The .NET classes are pretty much all going to be under System.Net. What you use depends on the design of your server. Warning: This project is going to require advanced skills in networking and socket communications.
GDMFSOB wrote: I think somekind of a dns interseptor would work but dont know how to handle traffic routing in .net.
Nope. This requires that you configure any software that's going to use the outside network to go through your proxy server. There is no "intercepting" anything to get this to work. Clients can very easily try to connect to outside networks and systems without using DNS at all, so intercepting DNS requests does you no good.
|
|
|
|
|
I have listbox with the follwing data from the base:
rownumber,a1,a2,a3,a4,a5,a6
1 1,2,3,6,5,4
2 3,2,9,5,7,5
3 4,5,2,8,9,7
4 9,9,8,2,3,5
5 9,8,5,1,2,4
6 7,3,6,8,4,9
etc,etc,etc
I have 2 textbox
textbox1 = the 3rd data in 2nd row
textbox2 = the 5th data in 4th row
How do I get these by code?
can someone help?
Tahnks
jaakinye
|
|
|
|
|
Simplest way would be to loop through each item in your listbox collection , since it is comma delimited (each char) it should be easy enough to get substring that you want.
|
|
|
|
|
If you know which item you want to get, then you can use ListBox.Items collection. You need to pass the index of the row you are intersted. After getting that value you can split the value using Split method and providing the separator, which will return the string array. Then you can grab the intended the value.
C#:
textBox1.Text = listBox1.Items[1].ToString().Split(new char[] { ',' })[2];
textBox2.Text = listBox1.Items[3].ToString().Split(new char[] { ',' })[4];
VB:
textBox1.Text = listBox1.Items(1).ToString().Split(New Char() {","c})(2)
textBox2.Text = listBox1.Items(3).ToString().Split(New Char() {","c})(4)
|
|
|
|
|
Thanks so much
Every thing is working well
jaakinye
|
|
|
|
|
I am trying to write a script that gets the info of all the users that exist on a PC. It gathers data on local users but not domain users. Any help would be appreciated on this matter. Here is a copy of my script:
'A Windows Script For Listing all Users on the current box
'Create a WMI Object
Set ow = GetObject("WinNT://.")
strOut = ""
'Get User Array
ow.Filter=Array("User")
For Each obj in ow
strOut = strOut & obj.Name & vbnewline
Next
Set ow = Nothing
Dim oFilesys, oFiletxt, sFilename, sPath
Set oFilesys = CreateObject("Scripting.FileSystemObject")
Set oFiletxt = oFilesys.CreateTextFile("c:\BeaconTemp\userlist.txt", True)
sPath = oFilesys.GetAbsolutePathName("c:\BeaconTemp\userlist.txt")
sFilename = oFilesys.GetFileName(sPath)
oFiletxt.WriteLine(strOut)
oFiletxt.Close
|
|
|
|
|
Here's [^] a bunch of scripts dedicated to User management, including searching AD. You'll find that the code is a bit different for AD than it is for local accounts.
|
|
|
|
|
I have a program that on the main form, I have a toolstrip and I want when you select tsiVersion (menu item), it displays a list of all the mdb files in a certian directory, like all open windows on a window menu.
Thanks in advance
In the end we're all just the same
|
|
|
|
|
First add a OpenFileDialog to your project and call it with the appropriate settings such as:
With OpenFileDialog1
.InitialDirectory = sDefaultDirectory
.Filter = "Access Database (*.mdb)|*.mdb"
.ShowDialog()
End With
Hope this helps.
Dominick
|
|
|
|
|
try following code
If Directory.Exists(path) Then 'path contains the path of directory<br />
Dim dir_info As New DirectoryInfo(path)<br />
Dim file_infos() As FileInfo<br />
file_infos = dir_info.GetFiles("*.mdb")<br />
End If
hope this helps
|
|
|
|
|
how to retrieve the values of a particular field from Ms Access database table onto a combobox?
|
|
|
|
|
vijay,
simply query to database and filled returned record in datatable and then add one by one or set combo box dataSource property to datatable
your question is not too specific. Try following link
Set combo box data source[^]
|
|
|
|
|
|
I don't understand what it is that you are trying to do.
You have not defined your problem in enough detail.
Why are you using a delegate? For example.
Without a more detailed and complete description of what it is you are trying to do, I doubt that anyone will be able to help you.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi,
Having worked as a VB6 programmer, and dealing mostly with events from forms and modules etc. I'm a little confused as to where to do exception handling with a class in .NET.
I have a class I've written that (amongst other things) sends a HttpWebRequest to a server and I want it to read the XML feed from the server. But where exactly do I handle the WebException that might occur? Should I put the try/catch into the actual class method that send the HttpWebRequest or should it be in the module code that calls the Function that will send the web request? See below for a brief example of what I mean.
Class MyClass
...
...
...
Sub GetXmlFromServer()
Try
' send request
Catch wex As System.Net.WebException
end try
End Sub
...
End Class
' in a module
Sub GetXml()
Dim mc as new MyClass()
mc.GetXmlFromServer()
End Sub
Or
Class MyClass
...
...
...
Sub GetXmlFromServer()
' send request
' etc etc
End Sub
...
End Class
' in a module
Sub GetXml()
Dim mc as new MyClass()
try
mc.GetXmlFromServer()
Catch wex As System.Net.WebException
End Try
End Sub
Personally I don't think I should put the exception handling in the class and that it should be handled in the sub/function (in a form or module) that calls the class method. But I'd like to know the
correct way to go about it.
Thanks
Max
|
|
|
|
|
Simply put, you have to use the Try Catch clause inside the sub or function part of your code. Like you used it in both examples. In other words, you don't have to choose. You can have your cake and eat it too.
The nice thing about vb.net's try catch clauses is that you can use several in a row within the same sub/function, and even nest them:
Private Sub BlaBlaBla()
Try
'some code here
Try
'some other code here
Catch ex as Exception
MsgBox(ex.ToString)
'and/or some code here
End Try
'and even more code here
Catch ex as Exception
MsgBox(ex.ToString)
'and/or some code here
End Try
Try
'and just to make sure, some other code here
Catch ex as Exception
MsgBox(ex.ToString)
'and/or some code here
End Try
'etc, etc, etc.
End Sub
Generally speaking, it is better to use too many try catch clauses than too few.
In classes and modules, it is a good idea to use the application event log for error reporting (
Public appLog As New System.Diagnostics.EventLog("Application", ".", appTitle) somewhere at the top and then
appLog.WriteEntry(ex.ToString, EventLogEntryType.Error) in the catch clause.) or a StreamWriter.
Hope this helps you.
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
Thanks Johan.
I understand what you're saying, I'll use as many try/catch blocks as I can - better to be safe than sorry!
I actually have a VB6 exception handling class (outputs to a text file) that I converted to .NET but thanks for informing me about the Application Log, it's good to know about the built in capabilities.
Max
|
|
|
|
|
Once you get a bit more accustomed to vb.net, you'll find that a lot of your old vb6 code is very cumbersome compared to its .net equivalent.
This is the log writing error handling sub that I use in one of my larger applications:
Public Sub EC(ByVal Err As Exception)
Try
Dim SW As New System.IO.StreamWriter("C:\error_log.txt", True)
SW.WriteLine(Err.ToString)
SW.Close()
Catch ex As Exception
appLog.WriteEntry(ex.ToString, EventLogEntryType.Error)
End Try
End Sub
Although ofcourse your class may contain less lines of code, I don't know...
If you have the use of an exchange server, you can even send yourself (or others) emails:
Public Shared Function ManualMail(ByVal oFrom As String, ByVal oSubject As String, ByVal oTo As String, ByVal oText As String, Optional ByVal oCC As String = "", Optional ByVal oBCC As String = "", Optional ByVal oAttachment As Object = Nothing) As Boolean
Dim mailmsg As New System.Web.Mail.MailMessage
With mailmsg
.BodyFormat = MailFormat.Html
.From = oFrom
.To = oTo
If Not oCC = "" Then .Cc = oCC
If Not oBCC = "" Then .Bcc = oBCC
.Subject = oSubject
.Body = oText
If Not oAttachment = Nothing Then .Attachments.Add(oAttachment)
End With
Try
System.Web.Mail.SmtpMail.SmtpServer = SmtpServerAddressHere 'example: mail.domain.com
System.Web.Mail.SmtpMail.Send(mailmsg)
Return True
Catch ex As Exception
appLog.WriteEntry(ex.ToString, EventLogEntryType.Error)
Return False
End Try
End Function
This one I actually also use in a class library.
My advice is free, and you may get what you paid for.
|
|
|
|
|
I don't think there is a general answer to the question.
You need to think about what the class/sub should do if an exception occurs.
Can MyClass do anything meaningful to recover from the exception? If it can then it probably should handle it, if not then don't catch it. (You might want to catch it so you can add additional info to the message and then re-throw the exception.)
If you catch the exception in MyClass what will GetXml do? It won't know the exception happened (unless you re-throw it). The same is true in MyClass if GetXmlFromServer catches the exception.
This will tell you if you actually need exception handling and where it should happen.
You should not use the exception handling mechanism to control program flow, but I'm sure you will see lots of examples where this does happen.
Regards
David R
|
|
|
|
|
Can MyClass do anything meaningful to recover from the exception? If it can then it probably should handle it, if not then don't catch it. (You might want to catch it so you can add additional info to the message and then re-throw the exception.)
Another question to ask is whether the caller is more likely to want to keep on with what it's doing despite the exception, or whether it will want to break out of any loop it's in. Personally I would think that in many situations the right approach would be to have routines take an error-function delegate which could throw an exception, silently swallow the error, or do something else. The try/do pattern isn't bad, but it provides no mechanism for distinguishing different types of failures nor for resolving them proactively.
Also, note that most of the time when you catch an exception and rethrow it, you should either use the word "throw" without an argument (if you don't want to change the exception type), or you should make a new exception that contains the original one as an InnerException.
|
|
|
|
|