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 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"
        Dim W As New IO.StreamWriter(SaveFile.FileName)
    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 =

    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("") 'email address

        mail.Append(strSubject1) 'subject
        mail.Append(strBody2) 'body of message
    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
    End Function
End Class

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



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 = ""
    oMsg.Subject = strSubject
    oMsg.Body = strBody2
    If System.IO.File.Exists(fileName) Then
    End If
End Sub
This article has been dead for over six months. Start a new discussion instead.