Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB.net local machine IP Address

Posted on 2014-04-09
5
Medium Priority
?
312 Views
Last Modified: 2014-04-14
Hi

I am trying to use the following code to send an email using System.Net.Mail
It asks for the local machine IP Address
How do I find this programmatically?

    Public Sub SendEmail(ByVal MsgFrom As String, ByVal MsgTo As String, ByVal MsgSubject As String, ByVal MsgBody As String)

        Try

            '  Pass in the message information to a new MailMessage

            Dim msg As New Net.Mail.MailMessage(MsgFrom, MsgTo, MsgSubject, MsgBody)



            '   Create an SmtpClient to send the e-mail

            Dim mailClient As New SmtpClient("127.0.0.1")  '  = local machine IP Address

            '  Use the Windows credentials of the current User

            mailClient.UseDefaultCredentials = True



            ' Pass the message to the mail server

            mailClient.Send(msg)

            '  Optional user reassurance:

            'MsgBox(String.Format("Message Subject ' {0} ' successfully sent From {1} To {2}", MsgSubject, MsgFrom, MsgTo), "EMail", Windows.Forms.MessageBoxButtons.OK)

            '  Housekeeping

            msg.Dispose()

        Catch ex As FormatException

            MsgBox(ex.Message & " :Format Exception")

        Catch ex As SmtpException

            MsgBox(ex.Message & " :SMTP Exception")

        End Try

Open in new window

0
Comment
Question by:Murray Brown
  • 2
  • 2
5 Comments
 
LVL 28

Expert Comment

by:MacroShadow
ID: 39990787
Private Sub GetIPAddress()

    Dim strHostName As String
    Dim strIPAddress As String

    strHostName = System.Net.Dns.GetHostName()
    strIPAddress = System.Net.Dns.GetHostByName(strHostName).AddressList(0).ToString()

    MessageBox.Show ("Host Name: " & strHostName & "; IP Address: " & strIPAddress)

End Sub

Open in new window


http://stackoverflow.com/questions/2234757/how-do-i-get-a-computers-name-and-ip-address-using-vb-net
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39991208
>Dim mailClient As New SmtpClient("127.0.0.1")

This needs to be the IP address of your email server. Do you have an SMTP server running on the local machine? If not, do you have access to a server? If yes, use that. If not, use a public server like gmail.
0
 

Author Comment

by:Murray Brown
ID: 39991370
Hi MacroShadow
I get 'GetHostByName' is obsolete for the line
 System.Net.Dns.GetHostByName(strHostName).AddressList(0).ToString()
0
 
LVL 28

Accepted Solution

by:
MacroShadow earned 2000 total points
ID: 39993353
But it works...
0
 

Author Closing Comment

by:Murray Brown
ID: 39998789
Thanks
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question