Emailing with default client

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dustin Davis

    #1

    Emailing with default client

    (using VB.NET 2005)

    I'm writing a desktop application that I would like to have the ability
    to email files. I've set up the SMTP portion, now I would like to have a
    MAPI option.

    I found a MAPI tutorial, but it does a bit more than I want it to. What
    I would like to do is this:

    1. Open the default mail client's compose window.
    2. Add an attachment

    Then the user can fill out the To: Subject: etc.

    Can anyone help me with this?

    Thanks,
    Dustin
  • Cor Ligthert [MVP]

    #2
    Re: Emailing with default client

    Dustin,

    Your problem is in this sentence
    [color=blue]
    > 2. Add an attachment[/color]

    Not all emailclients have the possiblitity to add attachments. It is as well
    not in the standard code for opening default email clients.

    This question is thousand times done in this newsgroup. If you know that it
    is Office Outlook than there are possibilites and I have read from Carlos
    that it can as well at OutlookExpress, but not right from the box.

    Cor


    Comment

    • Carlos J. Quintero [VB MVP]

      #3
      Re: Emailing with default client

      Hi Dustin,

      See if there is something here:

      How do I send an email with attachments?


      --

      Best regards,

      Carlos J. Quintero

      MZ-Tools: Productivity add-ins for Visual Studio
      You can code, design and document much faster:
      MZ-Tools has a single goal: To make your everyday programming life easier. As an add-in to several Integrated Development Environment (IDEs) from Microsoft, MZ-Tools adds new menus and toolbars to them that provide many new productivity features.




      "Dustin Davis" <dustin.davis@g mail.com> escribió en el mensaje
      news:OuMRB3yYGH A.4688@TK2MSFTN GP04.phx.gbl...[color=blue]
      > (using VB.NET 2005)
      >
      > I'm writing a desktop application that I would like to have the ability to
      > email files. I've set up the SMTP portion, now I would like to have a MAPI
      > option.
      >
      > I found a MAPI tutorial, but it does a bit more than I want it to. What I
      > would like to do is this:
      >
      > 1. Open the default mail client's compose window.
      > 2. Add an attachment
      >
      > Then the user can fill out the To: Subject: etc.
      >
      > Can anyone help me with this?
      >
      > Thanks,
      > Dustin[/color]


      Comment

      • Cor Ligthert [MVP]

        #4
        Re: Emailing with default client

        Carlos,

        That is systemwebmail. A default client is opened in this way.
        \\\
        ///a reference to System.Web
        ///using System.Web;
        ///using System.Diagnost ic
        Process.Start ("mailto:" + HttpUtility.Url Encode("NotMyFi rstName@planet. nl")
        + "?subject=D oes this helps" + "&body=How do you do?");
        ///

        Cor

        "Carlos J. Quintero [VB MVP]" <carlosq@NOSPAM sogecable.com> schreef in
        bericht news:eAj7xD5YGH A.4424@TK2MSFTN GP05.phx.gbl...[color=blue]
        > Hi Dustin,
        >
        > See if there is something here:
        >
        > How do I send an email with attachments?
        > http://systemwebmail.com/faq/2.3.aspx
        >
        > --
        >
        > Best regards,
        >
        > Carlos J. Quintero
        >
        > MZ-Tools: Productivity add-ins for Visual Studio
        > You can code, design and document much faster:
        > http://www.mztools.com
        >
        >
        >
        > "Dustin Davis" <dustin.davis@g mail.com> escribió en el mensaje
        > news:OuMRB3yYGH A.4688@TK2MSFTN GP04.phx.gbl...[color=green]
        >> (using VB.NET 2005)
        >>
        >> I'm writing a desktop application that I would like to have the ability
        >> to email files. I've set up the SMTP portion, now I would like to have a
        >> MAPI option.
        >>
        >> I found a MAPI tutorial, but it does a bit more than I want it to. What I
        >> would like to do is this:
        >>
        >> 1. Open the default mail client's compose window.
        >> 2. Add an attachment
        >>
        >> Then the user can fill out the To: Subject: etc.
        >>
        >> Can anyone help me with this?
        >>
        >> Thanks,
        >> Dustin[/color]
        >
        >[/color]


        Comment

        • Dustin Davis

          #5
          Re: Emailing with default client

          I've tried the mailto: method, but I can't seem to add an attachment.
          I'm watching another program do the very thing I am trying to do, but I
          don't know how it is doing it. It opens the default mail client compose
          window with the specified file attached. Amazingly it works when I have
          either Outlook Express or Thuderbird as my default mail client.

          I've tried using the VB6 MAPI controls (MAPISession & MAPIMessages), I
          can sent through Outlook Express, but not Thunderbird. When I send
          through Outlook express it makes me enter my password twice - the fist
          time is when it connects (it then wants to download all my new
          messages), then again when I got to send. Frustrating :(

          Cor Ligthert [MVP] wrote:[color=blue]
          > Carlos,
          >
          > That is systemwebmail. A default client is opened in this way.
          > \\\
          > ///a reference to System.Web
          > ///using System.Web;
          > ///using System.Diagnost ic
          > Process.Start ("mailto:" + HttpUtility.Url Encode("NotMyFi rstName@planet. nl")
          > + "?subject=D oes this helps" + "&body=How do you do?");
          > ///
          >
          > Cor
          >
          > "Carlos J. Quintero [VB MVP]" <carlosq@NOSPAM sogecable.com> schreef in
          > bericht news:eAj7xD5YGH A.4424@TK2MSFTN GP05.phx.gbl...[color=green]
          >> Hi Dustin,
          >>
          >> See if there is something here:
          >>
          >> How do I send an email with attachments?
          >> http://systemwebmail.com/faq/2.3.aspx
          >>
          >> --
          >>
          >> Best regards,
          >>
          >> Carlos J. Quintero
          >>
          >> MZ-Tools: Productivity add-ins for Visual Studio
          >> You can code, design and document much faster:
          >> http://www.mztools.com
          >>
          >>
          >>
          >> "Dustin Davis" <dustin.davis@g mail.com> escribió en el mensaje
          >> news:OuMRB3yYGH A.4688@TK2MSFTN GP04.phx.gbl...[color=darkred]
          >>> (using VB.NET 2005)
          >>>
          >>> I'm writing a desktop application that I would like to have the ability
          >>> to email files. I've set up the SMTP portion, now I would like to have a
          >>> MAPI option.
          >>>
          >>> I found a MAPI tutorial, but it does a bit more than I want it to. What I
          >>> would like to do is this:
          >>>
          >>> 1. Open the default mail client's compose window.
          >>> 2. Add an attachment
          >>>
          >>> Then the user can fill out the To: Subject: etc.
          >>>
          >>> Can anyone help me with this?
          >>>
          >>> Thanks,
          >>> Dustin[/color]
          >>[/color]
          >
          >[/color]

          Comment

          • Carlos J. Quintero [VB MVP]

            #6
            Re: Emailing with default client

            Ah, yes, but anyway an approach would be to use SystemWebMail and provide
            your own compose form with subject, destination textboxes and attach button
            since I don´t think that Simple MAPI will be able to add attachments, so
            either you need to use Extended MAPI (C++), not .NET compatible, or use CDO,
            which may not work for all e-mail clients.

            See:

            Differences between CDO, Simple MAPI, and Extended MAPI



            --

            Best regards,

            Carlos J. Quintero

            MZ-Tools: Productivity add-ins for Visual Studio
            You can code, design and document much faster:
            MZ-Tools has a single goal: To make your everyday programming life easier. As an add-in to several Integrated Development Environment (IDEs) from Microsoft, MZ-Tools adds new menus and toolbars to them that provide many new productivity features.



            "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> escribió en el mensaje
            news:eEdno75YGH A.3424@TK2MSFTN GP02.phx.gbl...[color=blue]
            > Carlos,
            >
            > That is systemwebmail. A default client is opened in this way.
            > \\\
            > ///a reference to System.Web
            > ///using System.Web;
            > ///using System.Diagnost ic
            > Process.Start ("mailto:" +
            > HttpUtility.Url Encode("NotMyFi rstName@planet. nl")
            > + "?subject=D oes this helps" + "&body=How do you do?");
            > ///
            >[/color]

            Comment

            • Dustin Davis

              #7
              Re: Emailing with default client

              So, in any case, I got it to work as I needed using the VB6 MAPI
              controls. Without going into too much detail, I'll just post the
              function here in case anyone else is interested. Let me know if you have
              question on what I did here (This works in Mozilla Thunderbird and
              Outlook Express):

              Private Function SendMapiEmail() As Boolean
              Dim FilePaths() As String = IO.Directory.Ge tFiles(Me.TempO utputPath)

              Try
              With Me.MapiSession
              If .SessionID = 0 Then
              .DownLoadMail = False
              .LogonUI = True
              .SignOn()
              End If
              End With

              With Me.MapiMessages
              .SessionID = Me.MapiSession. SessionID
              .Compose()
              .MsgSubject = "Images Attached"
              .MsgNoteText = "(See Attached)"
              For i As Integer = 0 To FilePaths.Lengt h - 1
              .AttachmentInde x = i
              .AttachmentPath Name = FilePaths(i)
              Next
              .Send(True)
              End With
              Me.MapiSession. SignOff()
              Catch ex As Exception
              MsgBox("Error sending MAPI email: " & ex.Message,
              MsgBoxStyle.Exc lamation, AppName)
              Return False
              End Try

              Return True
              End Function

              Carlos J. Quintero [VB MVP] wrote:[color=blue]
              > Ah, yes, but anyway an approach would be to use SystemWebMail and provide
              > your own compose form with subject, destination textboxes and attach button
              > since I don´t think that Simple MAPI will be able to add attachments, so
              > either you need to use Extended MAPI (C++), not .NET compatible, or use CDO,
              > which may not work for all e-mail clients.
              >
              > See:
              >
              > Differences between CDO, Simple MAPI, and Extended MAPI
              > http://support.microsoft.com/kb/200018/en-us
              >
              >[/color]

              Comment

              • Dennis

                #8
                Re: Emailing with default client

                What .dll did you have to reference to use VB6Mapi?
                --
                Dennis in Houston


                "Dustin Davis" wrote:
                [color=blue]
                > So, in any case, I got it to work as I needed using the VB6 MAPI
                > controls. Without going into too much detail, I'll just post the
                > function here in case anyone else is interested. Let me know if you have
                > question on what I did here (This works in Mozilla Thunderbird and
                > Outlook Express):
                >
                > Private Function SendMapiEmail() As Boolean
                > Dim FilePaths() As String = IO.Directory.Ge tFiles(Me.TempO utputPath)
                >
                > Try
                > With Me.MapiSession
                > If .SessionID = 0 Then
                > .DownLoadMail = False
                > .LogonUI = True
                > .SignOn()
                > End If
                > End With
                >
                > With Me.MapiMessages
                > .SessionID = Me.MapiSession. SessionID
                > .Compose()
                > .MsgSubject = "Images Attached"
                > .MsgNoteText = "(See Attached)"
                > For i As Integer = 0 To FilePaths.Lengt h - 1
                > .AttachmentInde x = i
                > .AttachmentPath Name = FilePaths(i)
                > Next
                > .Send(True)
                > End With
                > Me.MapiSession. SignOff()
                > Catch ex As Exception
                > MsgBox("Error sending MAPI email: " & ex.Message,
                > MsgBoxStyle.Exc lamation, AppName)
                > Return False
                > End Try
                >
                > Return True
                > End Function
                >
                > Carlos J. Quintero [VB MVP] wrote:[color=green]
                > > Ah, yes, but anyway an approach would be to use SystemWebMail and provide
                > > your own compose form with subject, destination textboxes and attach button
                > > since I don´t think that Simple MAPI will be able to add attachments, so
                > > either you need to use Extended MAPI (C++), not .NET compatible, or use CDO,
                > > which may not work for all e-mail clients.
                > >
                > > See:
                > >
                > > Differences between CDO, Simple MAPI, and Extended MAPI
                > > http://support.microsoft.com/kb/200018/en-us
                > >
                > >[/color]
                >[/color]

                Comment

                • Carlos J. Quintero [VB MVP]

                  #9
                  Re: Emailing with default client

                  So the MAPI controls allow to send attachments. Did you investigate of the
                  Simple MAPI allow that? They are 12 API functions or so and if it works it
                  would allow you to get rid of the VB6 controls in your app...

                  --

                  Best regards,

                  Carlos J. Quintero

                  MZ-Tools: Productivity add-ins for Visual Studio
                  You can code, design and document much faster:
                  MZ-Tools has a single goal: To make your everyday programming life easier. As an add-in to several Integrated Development Environment (IDEs) from Microsoft, MZ-Tools adds new menus and toolbars to them that provide many new productivity features.





                  "Dustin Davis" <dustin.davis@g mail.com> escribió en el mensaje
                  news:OFuWjs8YGH A.3532@TK2MSFTN GP05.phx.gbl...[color=blue]
                  > So, in any case, I got it to work as I needed using the VB6 MAPI controls.
                  > Without going into too much detail, I'll just post the function here in
                  > case anyone else is interested. Let me know if you have question on what I
                  > did here (This works in Mozilla Thunderbird and Outlook Express):
                  >
                  > Private Function SendMapiEmail() As Boolean
                  > Dim FilePaths() As String = IO.Directory.Ge tFiles(Me.TempO utputPath)
                  >
                  > Try
                  > With Me.MapiSession
                  > If .SessionID = 0 Then
                  > .DownLoadMail = False
                  > .LogonUI = True
                  > .SignOn()
                  > End If
                  > End With
                  >
                  > With Me.MapiMessages
                  > .SessionID = Me.MapiSession. SessionID
                  > .Compose()
                  > .MsgSubject = "Images Attached"
                  > .MsgNoteText = "(See Attached)"
                  > For i As Integer = 0 To FilePaths.Lengt h - 1
                  > .AttachmentInde x = i
                  > .AttachmentPath Name = FilePaths(i)
                  > Next
                  > .Send(True)
                  > End With
                  > Me.MapiSession. SignOff()
                  > Catch ex As Exception
                  > MsgBox("Error sending MAPI email: " & ex.Message,
                  > MsgBoxStyle.Exc lamation, AppName)
                  > Return False
                  > End Try
                  >
                  > Return True
                  > End Function
                  >[/color]

                  Comment

                  • Dustin Davis

                    #10
                    Re: Emailing with default client

                    Here's the steps you should follow to get the code to work that I posted
                    previously:

                    1. Add a reference to the COM "Microsoft MAPI Controls 6.0"
                    2. In your Toolbox, right-click and select "Choose items..."
                    3. In the COM Components tab, select the "Microsoft MAPI Messages
                    Control" and the "Microsoft MAPI Session Control"
                    4. Add the controls to your form

                    Dennis wrote:[color=blue]
                    > What .dll did you have to reference to use VB6Mapi?[/color]

                    Comment

                    • Dennis

                      #11
                      Re: Emailing with default client

                      I don't have VB6 installed on my computer and don't want to install it
                      really. Can I get the controls and just add them to the bin directory? If
                      so, where can I find them>
                      --
                      Dennis in Houston


                      "Dustin Davis" wrote:
                      [color=blue]
                      > Here's the steps you should follow to get the code to work that I posted
                      > previously:
                      >
                      > 1. Add a reference to the COM "Microsoft MAPI Controls 6.0"
                      > 2. In your Toolbox, right-click and select "Choose items..."
                      > 3. In the COM Components tab, select the "Microsoft MAPI Messages
                      > Control" and the "Microsoft MAPI Session Control"
                      > 4. Add the controls to your form
                      >
                      > Dennis wrote:[color=green]
                      > > What .dll did you have to reference to use VB6Mapi?[/color]
                      >[/color]

                      Comment

                      • Dustin Davis

                        #12
                        Re: Emailing with default client

                        I'm not sure. I don't have vb6 installed either. VB.NET 2005 is the only
                        version I have ever installed on my machine.

                        Dennis wrote:[color=blue]
                        > I don't have VB6 installed on my computer and don't want to install it
                        > really. Can I get the controls and just add them to the bin directory? If
                        > so, where can I find them>[/color]

                        Comment

                        Working...