473,574 Members | 3,131 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 3255
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
1560
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
2299
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
1403
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:"...
4
7274
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...
6
1970
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... ...
2
17464
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...
8
5186
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...
5
3106
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
7842
marktang
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...
0
7764
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...
0
8110
Oralloy
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. ...
1
7862
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...
0
8138
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...
0
6514
agi2029
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...
0
3775
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...
1
2277
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
1
1375
muto222
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.