locked
How to make user when it press on emailto LinkLabel to take it to it's default email client in vb.net2005? RRS feed

  • Question

  •  Hi all,

    I;m using this code to let user to send me email.

     Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
            Process.Start("www.hotmail.com")
        End Sub

    But How to make user when it press on emailto LinkLabel to take it to its default email client direct whether it uses gmail ,yahoo mail, or hotmail or whatever and when the page of its default email opens I want to this code writes my email in "sendto" field already? 

    Thanks advance


    • Edited by Max45-1 Thursday, July 20, 2017 1:32 AM
    Thursday, July 20, 2017 1:28 AM

Answers

  • Hi omanxp45-2,

    You can use the code below to open the default email client if you have set the default email client in your windows system.

    Dim theStringBuilder As New StringBuilder()
            theStringBuilder.Append("mailto:email@Address.com")
            theStringBuilder.Append("&subject=my subject")
            theStringBuilder.Append("&body=my email body message")
            Process.Start(theStringBuilder.ToString())

    this will start up the default email client (outlook usually) with the field populated.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Max45-1 Friday, July 21, 2017 12:48 AM
    Thursday, July 20, 2017 6:34 AM
  • Here the code that does this action in condition that user have a default e-mail client configured. 

    Imports system.diagnostics
    Public Class Form1
    
     Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
            Try
                Dim theStringBuilder As New System.Text.StringBuilder()
    
                theStringBuilder.Append("mailto:email@Address.com")
    
                theStringBuilder.Append("&subject=My subject")
    
                theStringBuilder.Append("&body=My email body")
    
                System.Diagnostics.Process.Start(theStringBuilder.ToString())
            Catch ex As Exception
                MsgBox(ex.Message)
    
    
            End Try
           
        End Sub
    
    
    


    • Marked as answer by Max45-1 Friday, July 21, 2017 12:53 AM
    Friday, July 21, 2017 12:53 AM

All replies

  • In order to start the default email client of the user’s machine without knowing the user’s personal preferences, try this:

    Process.Start("mailto:myaddress@hotmail.com&subject=Some Subject&body=Sample Body")
    

    Thursday, July 20, 2017 5:00 AM
  • In order to start the default email client of the user’s machine without knowing the user’s personal preferences, try this:

    Process.Start("mailto:myaddress@hotmail.com&subject=Some Subject&body=Sample Body")

    It gave me this error

    System.ComponentModel.Win32Exception was unhandled
      ErrorCode=-2147467259
      Message="Application not found"
      Source="System"
      StackTrace:
           at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
         
       

    Thursday, July 20, 2017 5:43 AM
  • Hi omanxp45-2,

    You can use the code below to open the default email client if you have set the default email client in your windows system.

    Dim theStringBuilder As New StringBuilder()
            theStringBuilder.Append("mailto:email@Address.com")
            theStringBuilder.Append("&subject=my subject")
            theStringBuilder.Append("&body=my email body message")
            Process.Start(theStringBuilder.ToString())

    this will start up the default email client (outlook usually) with the field populated.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Max45-1 Friday, July 21, 2017 12:48 AM
    Thursday, July 20, 2017 6:34 AM

  • Dim theStringBuilder As New StringBuilder()
            


    Error 1 Type 'StringBuilder' is not defined.


    I've change it and import namespace but it gives me error of "application not found"

     Imports system.diagnostics
            Dim theStringBuilder As New System.Text.StringBuilder()
    
            theStringBuilder.Append("mailto:email@Address.com")
    
            theStringBuilder.Append("&subject=My subject")
    
            theStringBuilder.Append("&body=My email body")
    
            System.Diagnostics.Process.Start(theStringBuilder.ToString())







    • Edited by Max45-1 Thursday, July 20, 2017 11:44 AM
    Thursday, July 20, 2017 11:21 AM
  • Unfortunately this isn't going to always work, especially with web e-mail. For web e-mail it will largely depend upon whether the browser was configured or has an add-in or extension installed that supports mail-to. If you get an exception that the app is not found then you will need to notify the user that they do not have a default e-mail client configured.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    • Proposed as answer by Frank L. Smith Thursday, July 20, 2017 12:30 PM
    Thursday, July 20, 2017 12:19 PM
  • Here the code that does this action in condition that user have a default e-mail client configured. 

    Imports system.diagnostics
    Public Class Form1
    
     Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
            Try
                Dim theStringBuilder As New System.Text.StringBuilder()
    
                theStringBuilder.Append("mailto:email@Address.com")
    
                theStringBuilder.Append("&subject=My subject")
    
                theStringBuilder.Append("&body=My email body")
    
                System.Diagnostics.Process.Start(theStringBuilder.ToString())
            Catch ex As Exception
                MsgBox(ex.Message)
    
    
            End Try
           
        End Sub
    
    
    


    • Marked as answer by Max45-1 Friday, July 21, 2017 12:53 AM
    Friday, July 21, 2017 12:53 AM