How can the contents of a textBox (or RichTextBox) be sent as email by using a button click-event in VB.NET

I am wirting an app which combines the inpiut from various sources into a textbox. I want to send selected text  from this textbox as email by clicking a button. Either the button's text property would be set to the email address, or this could be picked up from another textbox, or, alternatively it could be entered by the user. I think I need to use

Any hints would be appreciated.  
Who is Participating?
Jeffrey CoachmanMIS LiasonCommented:
Here is a fully functioning sample
Jeffrey CoachmanMIS LiasonCommented:
Use the standard Outlook automation code found here:
And simply add in your Texbox reference as the Message Body.

(I have not tesed this code specifically. MS has about three different versions of it, all similar.
If you can't get this to work then I will post the code I use.)

Something like this:

Sub sbSendMessage(Optional AttachmentPath)
   Dim objOutlook As Outlook.Application
   Dim objOutlookMsg As Outlook.MailItem
   Dim objOutlookRecip As Outlook.Recipient
   Dim objOutlookAttach As Outlook.Attachment

   On Error GoTo ErrorMsgs

   ' Create the Outlook session.
   Set objOutlook = CreateObject("Outlook.Application")
   ' Create the message.
   Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
   With objOutlookMsg
      ' Add the To recipient(s) to the message. Substitute
      ' your names here.
     Set objOutlookRecip = .Recipients.Add("Nancy Davolio")
      objOutlookRecip.Type = olTo
      ' Add the CC recipient(s) to the message.
      Set objOutlookRecip = .Recipients.Add("Andrew Fuller")
      objOutlookRecip.Type = olCC
      ' Set the Subject, Body, and Importance of the message.
      .Subject = "This is an Automation test with Microsoft Outlook"
.Body = YourTexBoxReference
      .Importance = olImportanceHigh  'High importance
      ' Add attachments to the message.
      If Not IsMissing(AttachmentPath) Then
         Set objOutlookAttach = .Attachments.Add(AttachmentPath)
      End If
      ' Resolve each Recipient's name.
      For Each objOutlookRecip In .Recipients
         If Not objOutlookRecip.Resolve Then
.........End If
      End If
   End With
   Set objOutlookMsg = Nothing
   Set objOutlook = Nothing
   Set objOutlookRecip = Nothing
   Set objOutlookAttach = Nothing
   If Err.Number = "287" Then
      MsgBox "You clicked No to the Outlook security warning. " & _
      "Rerun the procedure and click Yes to access e-mail" & _
      "addresses to send your message. For more information, & _
      "see the document at" & _
      "/previous/outlook/downloads/security.asp. " "
      Msgbox Err.Number, Err.Description
   End If
End Sub

softspotAuthor Commented:
Thanks for this. Still some quirks not solved. Would appreciate it if you would post your code as you suggest.

softspotAuthor Commented:
Thanks for your help. This has opened up other issues which I need to think about. Good luck!
Jeffrey CoachmanMIS LiasonCommented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.