Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27349

VS 2010 Open Default Email Program and Attach File.

$
0
0
I have a winforms app with sql database.

I am trying to have a button on the form that allows the user to export a report to pdf, popup a new email message in the default email program on the computer and attach the file.

I have been working on this for two days. I can't use SMTP because the user would manually enter the email address of who they are sending it to. I have this working for Outlook 2010 but I have another client who is using Eudora (I know, but nevertheless that is what they want to use).


I am currently using the code below which works but doesn't attach the file.
Code:

  Public Function OpenEmail(ByVal EmailAddress As String, _
  Optional ByVal Subject As String = "", _
  Optional ByVal Body As String = "", _
  Optional ByVal Attachments As String = "") _
  As Boolean

        Dim bAns As Boolean = True
        Dim sParams As String
        sParams = EmailAddress
        If LCase(Strings.Left(sParams, 7)) <> "mailto:" Then _
            sParams = "mailto:" & sParams

        If Subject <> "" Then sParams = sParams & _
              "?subject=" & Subject

        If Body <> "" Then
            sParams = CStr(sParams & CStr(IIf(Subject = "", "?", "&")))
            sParams = sParams & "body=" & Body
        End If

        If Attachments <> "" Then
            'sParams = CStr(sParams & CStr(IIf(Body = "", "?", "&")))
            sParams = sParams & "attachments=" & Attachments
        End If

        Try

            System.Diagnostics.Process.Start(sParams)

        Catch
            bAns = False
        End Try

        Return bAns

    End Function

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        OpenEmail("", "Testing", "This is a test email from VS2010 to Windows Mail.", "C:\Member Program\Reports\MemberReport.pdf")
   
    End Sub

I am wondering if someone with more experience might have done this before and knows what is wrong with this code.

Thanks,
Stacy

Viewing all articles
Browse latest Browse all 27349

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>