Im trying to make a little program that gets the computers IP address i have got it to do all of that and have got it to use the default email program to add the email address, subject and body but i cannot get it to add an attachment.

Imports System.Net.Mail

Public Class FrmRemote
    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        End
    End Sub

    Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        SaveFile.InitialDirectory = "C:\"
        SaveFile.FileName = "Remote Help"
        SaveFile.Filter = "Rich Text Format (*.rtf) | *.rtf"
        SaveFile.ShowDialog()
        Dim W As New IO.StreamWriter(SaveFile.FileName)
        W.WriteLine(txtName.Text)
        W.WriteLine(txtPhone.Text)
        W.WriteLine(txtAddress.Text)
        W.WriteLine(txtProblem.Text)
        W.WriteLine(txtIP.Text)
        W.Close()
    End Sub

    Private Sub btnCollect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCollect.Click
        Dim WC As New System.Net.WebClient

        txtIP.Text =
        System.Text.Encoding.ASCII.GetString((WC.DownloadData("http://whatismyip.com/automation/n09230945.asp")))

        WC.Dispose()
    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
        Dim strSubject As String 'subject title
        Dim strBody As String 'Body of message
        Dim strSubject1 As String 'Subject line
        Dim strBody2 As String 'Body of Message

        strSubject = "Need Remote Pc Help" 'store subject in variable
        strBody = "Here is all the info that you need for the help txtName" 'store body in variable

        Dim mail As New System.Text.StringBuilder

        strSubject1 = "?subject=" & strSubject
        strBody2 = "&body=" & strBody

        mail.Append("mailto:backstback@hotmail.com") 'email address

        mail.Append(strSubject1) 'subject
        mail.Append(strBody2) 'body of message
        SendMail(mail.ToString)
    End Sub
    Private Function SendMail(ByVal MailtoStr As String) As Boolean
        Dim MailP As New Process 'declare a new process
        MailP.StartInfo.FileName = MailtoStr 'open default mail client
        MailP.StartInfo.UseShellExecute = True
        MailP.StartInfo.RedirectStandardOutput = False
        MailP.Start()
        MailP.Dispose()
    End Function
End Class

So what im asking is does anyone know how to add get this code to add an attachment?

Thanks,

Ryan

I believe you would have more success with attachments if you only use the built-in mail functions in .NET, instead of relying on the default mail client.
Especially in the mixed mail client environment.

But, if you knew that everyone using your program is using Microsoft Outlook, you can add a reference to Microsoft.Office.Interop.Outlook and create an object instance of Outlook.
From there you can utilize those available properties and methods both for creating an email with attachments and to send the mail.

Imports Microsoft.Office.Interop

Private Sub SendMessage()
    Dim oEmail As New Outlook.Application
    Dim oMsg As Outlook.MailItem

    oMsg = oEmail.CreateItem(Outlook.OlItemType.olMailItem)
    oMsg.To = "backstback@hotmail.com"
    oMsg.Subject = strSubject
    oMsg.Body = strBody2
    If System.IO.File.Exists(fileName) Then
        oMsg.Attachments.Add(fileName)
    End If
    oMsg.Send()
    oMsg.Display()
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.