473,785 Members | 2,476 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to read a mail header

oni
hi all,

the program should be able to log on to a pop mail account and need to just
read its headers and display.

any help in this regard highly apperecialted. code pref VB.NET

thankz in advance
Nov 21 '05 #1
1 3262
Hi,

I converted this c# pop3 mail class to vb.net. Maybe this will
help.

http://www.programmersheaven.com/2/Art_CSharp_3

How to use

Dim mail As New Pop3Mail

mail.Connect("m ail.xxxx.net", "user", "password")

For Each msg As Pop3Mail.Pop3Me ssage In mail.List

Trace.WriteLine (DirectCast(mai l.Retrieve(msg) ,
Pop3Mail.Pop3Me ssage).message)

Next

The class

Imports System.Net.Sock ets

Public Class Pop3Mail

Inherits System.Net.Sock ets.TcpClient

Public Class Pop3Exception

Inherits System.Applicat ionException
Public Sub New(ByVal str As String)

MyBase.New(str)
End Sub 'New

End Class 'Pop3Exception

Public Class Pop3Message

Public number As Long

Public bytes As Long

Public retrieved As Boolean

Public message As String

End Class 'Pop3Message

Public Overloads Sub Connect(ByVal server As String, ByVal username As
String, ByVal password As String)

Dim message As String

Dim strResponse As String

Connect(server, 110)

strResponse = Response()

If strResponse.Sub string(0, 3) <> "+OK" Then

Throw New Pop3Exception(R esponse)

End If

message = "USER " + username + vbCr + vbLf

Write(message)

strResponse = Response()

If strResponse.Sub string(0, 3) <> "+OK" Then

Throw New Pop3Exception(s trResponse)

End If

message = "PASS " + password + vbCr + vbLf

Write(message)

strResponse = Response()

If strResponse.Sub string(0, 3) <> "+OK" Then

Throw New Pop3Exception(s trResponse)

End If

End Sub 'Connect

Public Sub Disconnect()

Dim message As String

Dim strResponse As String

message = "QUIT" + vbCr + vbLf

Write(message)

strResponse = Response()

If strResponse.Sub string(0, 3) <> "+OK" Then

Throw New Pop3Exception(s trResponse)

End If

End Sub 'Disconnect

Public Function List() As ArrayList

Dim message As String

Dim strResponse As String

Dim retval As New ArrayList

message = "LIST" + vbCr + vbLf

Write(message)

strResponse = Response()

If strResponse.Sub string(0, 3) <> "+OK" Then

Throw New Pop3Exception(s trResponse)

End If

While True

strResponse = Response()

If strResponse = "." & vbCr & vbLf Then

Return retval

Else

Dim msg As New Pop3Message

Dim seps As Char() = " ".ToCharArr ay

Dim values As String() = strResponse.Spl it(seps)

msg.number = Int32.Parse(val ues(0))

msg.bytes = Int32.Parse(val ues(1))

msg.retrieved = False

retval.Add(msg)

End If

End While

End Function 'List

Public Function Retrieve(ByVal rhs As Pop3Message) As Pop3Message

Dim message As String

Dim strResponse As String

Dim msg As New Pop3Message

msg.bytes = rhs.bytes

msg.number = rhs.number

message = "RETR " & rhs.number & vbCr & vbLf

Write(message)

strResponse = Response()

If strResponse.Sub string(0, 3) <> "+OK" Then

Throw New Pop3Exception(s trResponse)

End If

msg.retrieved = True

While True

strResponse = Response()

If strResponse = "." & vbCr & vbLf Then

Exit While

Else

msg.message += strResponse

End If

End While

Return msg

End Function 'Retrieve

Private Sub Write(ByVal message As String)

Dim en As New System.Text.ASC IIEncoding

Dim WriteBuffer(102 3) As Byte

WriteBuffer = en.GetBytes(mes sage)

Dim stream As NetworkStream = GetStream()

stream.Write(Wr iteBuffer, 0, WriteBuffer.Len gth)

Debug.WriteLine ("WRITE:" + message)

End Sub 'Write

Public Sub Delete(ByVal rhs As Pop3Message)

Dim message As String

Dim strResponse As String

message = "DELE " & rhs.number & vbCr & vbLf

Write(message)

strResponse = Response()

If strResponse.Sub string(0, 3) <> "+OK" Then

Throw New Pop3Exception(s trResponse)

End If

End Sub 'Delete

Private Function Response() As String

Dim enc As New System.Text.ASC IIEncoding

Dim serverbuff() As Byte = New [Byte](1023) {}

Dim stream As NetworkStream = GetStream()

Dim count As Integer = 0

While True

Dim buff() As Byte = New [Byte](1) {}

Dim bytes As Integer = stream.Read(buf f, 0, 1)

If bytes = 1 Then

serverbuff(coun t) = buff(0)

count += 1

If buff(0) = Asc(vbLf) Then

Exit While

End If

Else

Exit While

End If

End While

Dim retval As String = enc.GetString(s erverbuff, 0, count)

Debug.WriteLine ("READ:" + retval)

Return retval

End Function 'Response

End Class

Ken

---------------------------------
"oni" <on*@discussion s.microsoft.com > wrote in message
news:E4******** *************** ***********@mic rosoft.com...
hi all,

the program should be able to log on to a pop mail account and need to just
read its headers and display.

any help in this regard highly apperecialted. code pref VB.NET

thankz in advance
Nov 21 '05 #2

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

Similar topics

0
1569
by: Majordomo | last post by:
-- >>>> --36742377 **** Command '--36742377' not recognized. >>>> Content-Type: text/plain; charset=us-ascii **** Command 'content-type:' not recognized. >>>> Content-Transfer-Encoding: 7bit **** Command 'content-transfer-encoding:' not recognized. >>>> >>>> something is fool
3
2307
by: Programmer | last post by:
Hi all I wan't to know if i'm able to read mail from a mail server. My mail server is a pop3 server (UNIX) and i want to be able to get the mails from an aspx or an asmx. with out using external objs. Only classes from the .NET Is there a way?? Thanks in advance
3
1409
by: Spr | last post by:
My problem is that code does not execute cariage return in the body message: "<?xml version="1.0"?> <g:propertyupdate xmlns:g="DAV:" xmlns:e="http://schemas.microsoft.com/exchange/" xmlns:mapi="http://schemas.microsoft.com/mapi/" xmlns:mapit="http://schemas.microsoft.com/mapi/proptag/" xmlns:x="xml:" xmlns:cal="urn:schemas:calendar:" xmlns:dt="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/" xmlns:header="urn:schemas:mailheader:"...
4
7288
by: Seok Bee | last post by:
Dear Experts, I have created a script to extract the Event Logs from the system into an excel sheet. The logs are separated into 2 worksheets (Application Log and System Log). After this excel file being created, it will be sent out via email to the list of recipients. I run the script on my notebook (also developed on th same machine) it works fine. However, when I copy all the programs into the server which running on Windows 2000...
6
1979
by: citlaly | last post by:
Hi!! I'm a beginner in python and I'm trying to use the files from a "folder" as a list. What I want to do is read each one as a list, but just the name of the file, the data inside doesn't matter. How can I do it? I was trying using a list, but I don't know how "convert" the elements (files) to a list that I can read and manipulate... Thanks in advance for your help!! Citlaly....
2
17489
by: clevrmnkey | last post by:
I've had nothing but trouble from the System.Net.Mail objects, but I finally need to make them work, and I can't for the life of me see what I'm doing wrong. I pared back my mail transaction to the bare minimum: System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("<my mail server IP>", 25); smtp.Send("<one of my email addresses>", "<another of my email addresses>", "Hello", "World");
8
5192
by: travispennington | last post by:
To anyone that can assist me: I deeply appreciate your help!! I am developing an application with an outside vendor. The vendor has a very odd requirement. They need custom X-Headers added to an email received by their system. That's not the odd part. The oddity is they want to have a single X-Header containing multiple keys and values that are delimited by a carriage return, line feed and tab. The vendor claims other customers...
5
3123
by: sui | last post by:
this is my code import sys, os, glob, datetime, time import smtplib ## Parameters for SMTP session port=587 SMTPserver= 'smtp.gmail.com' SMTPuser= '...@gmail.com' pw= 'fill in here' SENDER= SMTPuser
0
9489
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10101
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,...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7509
isladogs
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...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4063
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
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.