473,378 Members | 1,434 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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;"
  17.  
  18. 'Connection
  19.  
  20. Dim MyConnection As New
  21. Odbc.OdbcConnection(MyConString)
  22. MyConnection.Open()
  23. Dim MyCommand As New Odbc.OdbcCommand
  24. MyCommand.Connection = MyConnection
  25.  
  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)
  44.  
  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
  52.  
  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
  66.  
  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:")
  76.  
  77.  
  78. Dim content As String
  79. Dim content2 As String
  80.  
  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
  85.  
  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
  93.  
  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
  182.  
  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()
  191.  
  192. End If
  193.  
  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.
  197.  
  198. 'Catch ODBC Exception
  199. Catch MyOdbcException As Odbc.OdbcException
  200. Dim i As Integer
  201. Console.WriteLine(MyOdbcException.ToString)
  202.  
  203. 'Catch program exception
  204. Catch MyException As Exception
  205. Console.WriteLine(MyException.ToString)
  206. End Try
  207. End Sub
  208.  
Nov 20 '05 #1
1 1213
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

1
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...
5
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>
0
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...
3
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...
5
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 =...
0
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...
4
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...
0
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...
1
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.