Results 1 to 2 of 2

Thread: Email Question

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2008
    Posts
    1

    Email Question

    Hi all,

    Could somebody please help me with an problem that I am trying to solve. Admittedly I am useless at programming but nevertheless I have decided to develop a small program that will help me no end at work.

    The program simply gets the external IP address of a client and then I want it to mail it to me. I have tried everything but to no avail (mapi, cdo etc) and I just dont know where I am going wrong. This is my latest attempt, I am trying to use the default mail client to send the mail:

    NB Please be aware that I am rubbish at programming and everything is probably incorrect but I am desperate for this to work.

    Code:
    Public Class Form1
    
        Private Declare Function ShellExecute Lib "SHELL32.DLL" Alias "ShellExecuteA" _
    (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
    ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
        Public Const SW_ShowNormal = 1
    
        Function GetHtmlPageSource(ByVal url As String) As String
    
            Dim st As System.IO.Stream
            Dim sr As System.IO.StreamReader
    
            Try
                ' make a Web request
                Dim req As System.Net.WebRequest = System.Net.WebRequest.Create(url)
                Dim resp As System.Net.WebResponse = req.GetResponse
    
                ' read from the result stream
                st = resp.GetResponseStream
                sr = New System.IO.StreamReader(st)
    
                ' read all the text in it
                Return sr.ReadToEnd
            Catch ex As Exception
                Return ""
            Finally
                ' always close readers and streams
                sr.Close()
                st.Close()
            End Try
        End Function
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim SR As New System.IO.StringReader(GetHtmlPageSource("http://www.whatismyip.com/automation/n09230945.asp"))
            Dim strIPAddress As String
    
            Dim temp As String, iReturn As Long
            Dim EmailReceiver As String, Subject As String, Message As String
    
            strIPAddress = SR.ReadToEnd()
            IPAddress.Text = strIPAddress
    
    
            EmailReceiver = "[email protected]"
            Subject = "IP"
            Message = strIPAddress
    
            temp = "mailto:" & EmailReceiver & "?subject=" & Message & "&body=" & Message
    
            iReturn = ShellExecute(0&, "Open", temp, vbNullString, vbNullString, SW_ShowNormal)
    
        End Sub
    
    
    End Class
    Any guidance as to how I should be doing this would be greatly appreciated.

    Many thanks,

    M

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Email Question

    Moved to VB.NET

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width