Skype:TextControlSupport
Orders:877-462-4772
TX Text Control - word processing components.
What is this?Syndicate this content

E-Mail TX Text Control's contents, as HTML

This source code snippet requires TX Text Control ActiveX
Author:TX Text Control Support Department
Language:Visual Basic
Version:1.1
Released:March 20, 2001
Last modified:January 11, 2008
Requirements:TX Text Control ActiveX with Visual Basic 6.0
Download code:server.zip Download [2.5 KB, ZIP]

This sample application originally appeared in the TX Text Control Newsletter - why not sign up today and receive sample code like this every week, directly to your Inbox.

This week we are looking at a really handy trick that you can pull off with TX Text Control. In fact, we can go as far as to say that one of the most popular topics that is raised here in the Support Department is how to send the contents of a TX Text Control via e-mail.

And exactly that is the topic of this weeks' TX Top Tip.

So, you have got your text in a TX Text Control and you want to send that to someone on the Internet via e-mail. How do you do that?

Well, as you guessed, it is not that difficult.

The best way to approach this problem is to send the text as an attachment. All you need to do that is the TX Text Control and the MAPISession control from the Microsoft MAPI controls.

To send the contents of a TX Text Control as an email attachment, create a form with a MAPIMessages and a MAPISession control, a Send button, and 2 text boxes for email address and subject. Call the code below from the Send button's Click event. The RecipAdress and MsgSubject could contain the mail information for the recipient address and the mail subject. Take a look at this Visual Basic code:

  1. ' cmdSend_Click
  2. '
  3. ' Establish a MAPI session and send the current document as a HTML
  4. ' attachment.
  5. '
  6. Private Sub cmdSend_Click()
  7. On Error GoTo err_cmdSend_Click
  8.  
  9. ' Log on to MAPI session
  10. MAPISession.SignOn
  11. MAPIMessages.SessionID = MAPISession.SessionID
  12.  
  13. ' Compose and send mail
  14. MAPIMessages.Compose
  15. MAPIMessages.RecipAddress = txtEmailAddress
  16. MAPIMessages.MsgSubject = txtSubject
  17. MAPIMessages.AttachmentPathName = CreateFileAttachment(tx)
  18. MAPIMessages.Send True
  19. Kill MAPIMessages.AttachmentPathName
  20.  
  21. MAPISession.SignOff
  22. Unload Me
  23. Exit Sub
  24.  
  25. err_cmdSend_Click:
  26. MsgBox Err.Description
  27. Exit Sub
  28. End Sub
  29.  
  30. ' CreateFileAttachment
  31. '
  32. ' Save the current document to a temporary HTML file and return
  33. ' the file path. This file is used as an email attachment and
  34. ' must be deleted after it has been sent.
  35. '
  36. Private Function CreateFileAttachment(tx As TXTextControl) As String
  37. Dim sTempFile As String
  38. sTempFile = VBWrapper_TempPath() & "EmailAttachment.html"
  39. tx.Save sTempFile, 0, 4, False
  40. CreateFileAttachment = sTempFile
  41. End Function

And that is all there is to it. We told you it was a piece of cake. If you have any problems, just send us an e-mail (mailto:support@textcontrol.com). We are there to help you. Whether you are an advanced user or just setting out, you are entitled to take advantage of our complementary support service. E-mail us. We are looking forward to hearing from you very shortly.

top

Top 10 Bestselling Product Award 2007Top 25 Publisher Product Award 2007Top 10 Bestselling Product Award 2007 in JapanTop 25 Bestselling Product Award 2006Top 25 Bestselling Publisher Award 2006Reader's Choice Award, dot.net magazin, 3rd place