473,887 Members | 2,304 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading emails...

I have been developing a program that takes a database of
email bodies and then displays them to the user in a
similar way to Outlook Express would.

The problem I'm having is showing only the message of the
email and not some of the unnecessary jargon of the
message body.

Does anyone know of a really simple and clean way to
display only the message of the email body.

Below is a copy of the code that I'm currently using:

Expand|Select|Wrap|Line Numbers
  1. Private Sub MessageList_SelectedIndexChanged(ByVal
  2. sender As System.Object, ByVal e As System.EventArgs)
  3. Handles MessageList.SelectedIndexChanged
  4. Try
  5. 'Lets make sure that we're not selecting
  6. multiple emails to view, as this would be a bit difficult.
  7. If (MessageList.SelectedItems.Count <> 0) And
  8. (MessageList.SelectedItems.Count = 1) Then
  9. 'Connector/ODBC 3.51 connection string
  10. Dim MyConString As String = "DRIVER=
  11. {MySQL ODBC 3.51 Driver};" & _
  12. "SERVER=localhost;" & _
  13. "DATABASE=temp;" & _
  14. "UID=temp;" & _
  15. "PASSWORD=temp;" & _
  16. "OPTION=3;"
  18. 'Connection
  20. Dim MyConnection As New
  21. Odbc.OdbcConnection(MyConString)
  22. MyConnection.Open()
  23. Dim MyCommand As New Odbc.OdbcCommand
  24. MyCommand.Connection = MyConnection
  26. 'Select the specific email using the data
  27. taken from the selected entry of the Messages List view
  28. box.
  29. If iFolder_Id <> "Deleted" Then
  30. MyCommand.CommandText = "SELECT *
  31. FROM webmail_mails WHERE reciever='" & iUser_Id & "' AND
  32. folder='" & iFolder_Id & "' AND subject='" &
  33. MessageList.SelectedItems(0).Text & "' LIMIT 1"
  34. Else
  35. MyCommand.CommandText = "SELECT *
  36. FROM webmail_mails WHERE reciever='" & iUser_Id & "' AND
  37. trashed='true' AND subject='" & MessageList.SelectedItems
  38. (0).Text & "' LIMIT 1"
  39. End If
  40. Console.WriteLine(MyCommand.CommandText)
  41. Dim MyDataReader As Odbc.OdbcDataReader
  42. MyDataReader = MyCommand.ExecuteReader
  43. (CommandBehavior.Default)
  45. 'Some variables being declared.
  46. Dim sSubject As String
  47. Dim sSender As String
  48. Dim sSenderName As String
  49. Dim sMsg As String
  50. Dim dDate As String
  51. Dim bAttachments As Boolean
  53. While MyDataReader.Read
  54. 'Assign the data to the variables
  55. sSubject = MyDataReader
  56. ("subject").ToString
  57. sSender = MyDataReader
  58. ("sender").ToString
  59. sSenderName = MyDataReader
  60. ("sendername").ToString
  61. sMsg = MyDataReader("body").ToString
  62. dDate = MyDataReader("date").ToString
  63. dDate = dDate.Substring(5, 20)
  64. bAttachments = True
  65. End While
  67. 'Display the message in a formatted way.
  68. 'First we need to find out what content
  69. type the email is
  70. Dim strString As String = sMsg
  71. Dim strString2 As String = sMsg
  72. Dim type As Integer
  73. Dim start As Integer
  74. Dim finish As Integer
  75. type = strString.IndexOf("Content-Type:")
  78. Dim content As String
  79. Dim content2 As String
  81. content = sMsg.Substring(type + 14, 11)
  82. 'Now that we have the content type just
  83. make it all lower for checking.
  84. content = content.ToLower
  86. 'Is the content type:
  87. 'Text/Plain?
  88. If content = "text/plain;" Then
  89. start = strString.IndexOf(vbNewLine &
  90. vbNewLine)
  91. content2 = sMsg.Substring(start)
  92. content2 = content2.Trim
  94. email.Text = content2
  95. End If
  96. 'Multipart/m?
  97. If content = "multipart/m" Then
  98. start = strString.IndexOf("<html>")
  99. 'MessageBox.Show(start)
  100. If start < 1 Then
  101. 'This means that although it's
  102. Multipart it may be <HTML>
  103. start = strString.IndexOf
  104. ("<HTML>")
  105. 'MessageBox.Show(start)
  106. If start < 1 Then
  107. 'There is no message!
  108. email.Text = ""
  109. Else
  110. finish = strString.IndexOf
  111. ("</HTML>")
  112. content2 = sMsg.Substring
  113. (start, ((finish - start) + 7))
  114. email.Text = content2
  115. End If
  116. Else
  117. finish = strString.IndexOf
  118. ("</html>")
  119. content2 = sMsg.Substring(start,
  120. ((finish - start) + 7))
  121. email.Text = content2
  122. End If
  123. End If
  124. 'Multipart/a?
  125. If content = "multipart/a" Then
  126. start = strString.IndexOf("<html>")
  127. 'MessageBox.Show(start)
  128. If start < 1 Then
  129. 'This means that although it's
  130. Multipart it may be <HTML>
  131. start = strString.IndexOf
  132. ("<HTML>")
  133. 'MessageBox.Show(start)
  134. If start < 1 Then
  135. 'There is no message!
  136. email.Text = "[There is no
  137. message to display.]"
  138. Else
  139. finish = strString.IndexOf
  140. ("</HTML>")
  141. content2 = sMsg.Substring
  142. (start, ((finish - start) + 7))
  143. email.Text = content2
  144. End If
  145. Else
  146. finish = strString.IndexOf
  147. ("</html>")
  148. content2 = sMsg.Substring(start,
  149. ((finish - start) + 7))
  150. email.Text = content2
  151. End If
  152. End If
  153. 'Text/HTML?
  154. If content = "text/html; " Then
  155. start = strString.IndexOf("<html>")
  156. 'MessageBox.Show(start)
  157. If start < 1 Then
  158. 'This means that although it's
  159. Multipart it may be <HTML>
  160. start = strString.IndexOf
  161. ("<HTML>")
  162. 'MessageBox.Show(start)
  163. If start < 1 Then
  164. 'There is no message!
  165. email.Text = "[There is no
  166. message to display.]"
  167. Else
  168. finish = strString.IndexOf
  169. ("</HTML>")
  170. content2 = sMsg.Substring
  171. (start, ((finish - start) + 7))
  172. email.Text = content2
  173. End If
  174. Else
  175. finish = strString.IndexOf
  176. ("</html>")
  177. content2 = sMsg.Substring(start,
  178. ((finish - start) + 7))
  179. email.Text = content2
  180. End If
  181. End If
  183. 'Now lets add the data to the infobar
  184. infobar.Text = "Subject: " & sSubject &
  185. vbNewLine & "From:     " & sSenderName & vbNewLine
  186. & "Date:      " & dDate
  187. 'infobar2.Text = "From: " & sSenderName
  188. 'Close the connection and the reader
  189. MyDataReader.Close()
  190. MyCommand.Connection.Close()
  192. End If
  194. 'The following deals with any errors that
  195. have occured in the process of the above.
  196. 'At present they only output to the console.
  198. 'Catch ODBC Exception
  199. Catch MyOdbcException As Odbc.OdbcException
  200. Dim i As Integer
  201. Console.WriteLine(MyOdbcException.ToString)
  203. 'Catch program exception
  204. Catch MyException As Exception
  205. Console.WriteLine(MyException.ToString)
  206. End Try
  207. End Sub
Nov 20 '05 #1
1 1246
What do you mean "what objects to you refference?"?
Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: dan glenn | last post by:
I'm creating HTML emails from a PHP site and sending them out to an email list (just about 40 people so far are on this list). I've tested and confirmed that these emails work in yahoo.com's webmail. And I know they work on *my* Outlook Express. But I have one person (I know of) who gets the emails as plain text, so she sees the HTML code for the email instead of its proper representation. She has, like myself, OE6, and other html emails...
by: David Costelloe | last post by:
Hi, I am having trouble with this code can't seem to load these email values any Ideas? XML File <?xml version="1.0" ?> <Sections> <FilePath> <Path>c:\temp\</Path> </FilePath>
by: Pavils Jurjans | last post by:
Hello, I have a third-paty application that uses text type field in MSSQL server to store data of incoming emails (full raw sources, including headers, etc.). Since the emails come in different encodings, the character codes in the sources of these emails are possibly in full byte range. If I read the text field value from my C# application, I get distorted data, because some intermediate code applies character conversion to it to...
by: Simon Harris | last post by:
Hi All, Ok, this must be a simple one, I'm trying to read a certain elements contents from an XML file. Heres what I've come up with so far, which seems to get stuick in a loop (ASPNET.EXE hogs the CPU until I kill it!) Public Function GetPageName(ByVal XMLFileName As String) As String Dim XmlReader As New XmlTextReader(Session("DataLocation").ToString
by: Kun | last post by:
i have the following code: ---------------------------------- import smtplib from email.MIMEText import MIMEText fp = open('confirmation.txt', 'rb') msg = MIMEText(fp.read()) From = 'xxxx@xxxx.xxxx.edu'
by: James | last post by:
Using XML and the HttpWebRequest object, I'm easily able to authenticate an exchange user behind the scenes and retrieve a list of emails and the corresponding fields. For whatever sets of reasons, undeliverable email has something funky going on with it and I can't read the actual body of the email. What I'm really trying to do is implement a tracking system that will track: Number of emails sent out (easy) Number of emails received...
by: shmick30 | last post by:
Hi There, I am looping through and reading the body contents of a mail box with over 200 emails in it. The script is running very slow and timing out after 180 seconds, only getting through about 180 of these emails. Is there anyway I can increase the speed of this script? Why is it taking so long to loop through all these emails? Code is below: if($mailbox= imap_open( "{###.###.#.###:143/imap}mail_box", $a, $b)) {
by: =?Utf-8?B?Q2hhcmxlcw==?= | last post by:
Like many people, I normally use Yahoo! Mail via the web and like to keep all my emails stored on the Yahoo! server. However sometimes I can’t get access to a PC/the web and I download my emails to a PDA/palmtop via POP3. The PDA uses Windows Mobile software. Since using the PDA, I have had the problem of emails disappearing from the Yahoo! server. However I think I now understand how to avoid this. It seems that Windows Mobile is...
by: tim | last post by:
Hi, I have tried to make some code (with VB6) that will retrieve email from my personal email inbox. This works fine, but I need to read emails from a shared folder. I have goggled a lot but I can't find a solution that I need. This is what I need to do. Get the emails that are send to a public folder on our exchange server. Each email has a attachment that I need to place on a location on our network. It works fine for my own inbox...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.