• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 385
  • Last Modified:

VB.NET + Read Email - insert into Database

I am building an application that checks to see if an email has come into outlook, this part i have so far, but is it possible to read the email and insert value from the email into a database.

The email is a standard format and is just text, what i want to do is take the value and insert them into the database.

ie:

Account #: 12345678
Customer Name: John Smith
Customer Email: jsmith@email.com

Each email is setup the same way with the same fields, so i want to take the 12345678 and insert it, how do i do this.

thanks
0
dkilby
Asked:
dkilby
  • 6
  • 6
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
Hi dkilby,

Instead of using Outlook, see http://www.lesnikowski.com/Projects/Mail/Index.aspx

Cheers!
0
 
dkilbyAuthor Commented:
The email is coming from Exchange Server - isn't the link above only for POP3 accounts
0
 
Éric MoreauSenior .Net ConsultantCommented:
I use it to read from an Exchange server.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
dkilbyAuthor Commented:
ok i am trying to connect to the exchange server and get the following error.

Additional information: No connection could be made because the target machine actively refused it

this is what i put in

        Dim pop3 As Pop3 = New Pop3
        pop3.User = 'my domain account login'
        pop3.Password = 'my domain account password'
        pop3.Connect('exchange server address')

is this correct, the error occurs when it get to pop3.Connect
0
 
Éric MoreauSenior .Net ConsultantCommented:
Is the Pop3 service is started on your Exchange Server? It has to be started.
0
 
dkilbyAuthor Commented:
i don't believe it is, and i don't have access to the actual Exchange Server - does this mean this will not work for me?
0
 
Éric MoreauSenior .Net ConsultantCommented:
The Pop3 service must be started to be able to use the protocol against an Exchange server.
0
 
dkilbyAuthor Commented:
Ok i have figured out how to pull the body of the email into a string, now just need to figure out how to pull the values of from the string.

i was thinking i know the fields so is it possible to find the position of the fields and then take the value in between.

ie

strBody = "Account #: 12345678Customer Name: John SmithCustomer Email: jsmith@email.com"

so Account value would be between 10 and 20 if counting characters.

they may be an easier way too.

Thanks
0
 
Éric MoreauSenior .Net ConsultantCommented:
>>i was thinking i know the fields so is it possible to find the position of the fields and then take the value in between.

That is probably the easier way to go.
0
 
dkilbyAuthor Commented:
but how do i find the position of each field name so the end of Account #: and the beginning of Customer Name: so i know the area to use as the value
0
 
Éric MoreauSenior .Net ConsultantCommented:
try something like this:

        Dim intStop As Integer
        Dim strBody As String
        Dim strResult1 As String
        Dim strResult2 As String
        Dim strResult3 As String

        strBody = "Account #: 12345678Customer Name: John SmithCustomer Email: jsmith@email.com"

        intStop = strBody.IndexOf("Customer Name:")
        strResult1 = strBody.Substring(0, intStop)
        strBody = strBody.Remove(0, intStop)
        strResult1 = strResult1.Replace("Account #:", "").Trim

        intStop = strBody.IndexOf("Customer Email:")
        strResult2 = strBody.Substring(0, intStop)
        strBody = strBody.Remove(0, intStop)
        strResult2 = strResult2.Replace("Customer Name:", "").Trim

        strResult3 = strBody.Replace("Customer Email:", "").Trim

        MessageBox.Show(strResult1 & Environment.NewLine & strResult2 & Environment.NewLine & strResult3 & Environment.NewLine)
0
 
dkilbyAuthor Commented:
Thanks for all your help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now