Murray Brown
asked on
VB.net local machine IP Address
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?
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
>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.
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.
ASKER
Hi MacroShadow
I get 'GetHostByName' is obsolete for the line
System.Net.Dns.GetHostByNa me(strHost Name).Addr essList(0) .ToString( )
I get 'GetHostByName' is obsolete for the line
System.Net.Dns.GetHostByNa
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
Open in new window
http://stackoverflow.com/questions/2234757/how-do-i-get-a-computers-name-and-ip-address-using-vb-net