LebGeeks

A community for technology geeks in Lebanon.

You are not logged in.

#1 March 2 2009

mir
Member

Receive Mail with attachement

Hello guys,

I am doing a small thing where the application sends email with attachment to a list of ppl and to another application.

I want the other application to be able to download the attachment.

the first part is done (the sending)

I am kinda short on time, did anyone do a "receive" and download attachement app where the attached file is saved on a specified location for further processing and analysis by the second application

I am using VB2008

Thanks. your help is much appreciated.

I hope u got what i mean.. any questions for clarifications are welcomed

Last edited by mir (March 2 2009)

Offline

#2 March 3 2009

mir
Member

Re: Receive Mail with attachement

hmmm.. i can read the body of the email... in several ways, but not the attachements.

I did something in C# for the attachemetns.. but looks complicated.

please someone tell me that there is an easy and reliable way to do this :/ that i am not able to put finger on.

Thanks in advance

Offline

#3 March 3 2009

xterm
Moderator

Re: Receive Mail with attachement

EDIT: Blekh, i dont know why i missed your second post ><. Disregard what i said in this post.

Hi Mir,

I've worked on a bunch of protocols in my time using Java. I can guide you in the right direction but you have to choose your own path.

I'm assuming the mailbox is located on a pop3 server.

Simplest possible way of doing it, get what the others have done:
http://www.google.com/search?hl=en&q=po … tnG=Search

Longer manual solution:
However if you're interested in hacking your way through, start off by opening up a telnet session and connecting to the mail server:

> telnet my.mailserver.com 110   # 110 is the default pop3 port, its hardly ever changed.

USER yourusername                    # Send the server your username
PASS yourpassword                     # Your password
LIST                                           # this will list the emails (i think unread only) you have
RETR [NUMBER]         #Retrieve message(header i think)based on number through LIST command.IE: RETR 5

You can find additional information on POP3 in RFC1939, use http://www.rfc-editor.org/ or any RFC website to get information on the rfc.

After you're comfortable with pop3 commands, open up a library in vb and create a class that would communicate with the server and send the proper commands based on the server response (all listed in the RFC).

Note that your application *must* be threaded as you do not wish to hold your parent process while waiting for the server response.

Not sure how much this helps, but if you need any further information, dont hesitate to ask.

Last edited by xterm (March 3 2009)

Offline

#4 March 3 2009

xterm
Moderator

Re: Receive Mail with attachement

As an extension to what i said. You will need to check whether the message's content type is multipart. If you follow the steps i've mentioned before it will make sense.

The message header contains a Content-Type property that is set to "multipart/mixed". This alone will notify you that there's an attachment and as such you can start hovering over the entire message to locate the multipart with the Base64 encoding from which you can derive the file name and bytes. Here's an example of a attachment multipart:

------_=_NextPart_001_01C99B31.1B0D7A9D
Content-Type: text/plain;
        name="log-file.txt"
Content-Transfer-Encoding: base64
Content-Description: log-file.txt
Content-Disposition: attachment;
        filename="log-file.txt"

RklMRSBIRUFERVINCjIwMDktMDMtMDIgMTE6NTM6MTgsOTkwIFsxMl0gRVJST1IgV29ya2Zsb3dB
Y3Rpdmllcy5Xb3JrZmxvd0FjdGl2aXR5IChJTlRSQVNRTFNSVikgWyhudWxsKV0gLSBNYWlsYm94
IHVuYXZhaWxhYmxlLiBUaGUgc2VydmVyIHJlc3BvbnNlIHdhczogNS4xLjEgVXNlciB1bmtub3du
DQoyMDA5LTAzLTAyIDEyOjAwOjEyLDYxOCBbNl0gRVJST1IgU0FHQWN0aXZlRGlyZWN0b3J5LkFE
Q29udHJvbGxlciAoSU5UUkFTUUxTUlYpIFsobnVsbCldIC0gU3lzdGVtLkRpcmVjdG9yeVNlcnZp
Y2VzLkRpcmVjdG9yeVNlcnZpY2VzQ09NRXhjZXB0aW9uICgweDgwMDcwNTJFKTogTG9nb24gZmFp
bHVyZTogdW5rbm93biB1c2VyIG5hbWUgb3IgYmFkIHBhc3N3b3JkLg0KDQogICBhdCBTeXN0ZW0u
RGlyZWN0b3J5U2VydmljZXMuRGlyZWN0b3J5RW50cnkuQmluZChCb29sZWFuIHRocm93SWZGYWls
KQ0KICAgYXQgU3lzdGVtLkRpcmVjdG9yeVNlcnZpY2VzLkRpcmVjdG9yeUVudHJ5LkJpbmQoKQ0K
ICAgYXQgU3lzdGVtLkRpcmVjdG9yeVNlcnZpY2VzLkRpcmVjdG9yeUVudHJ5LmdldF9BZHNPYmpl
Y3QoKQ0KICAgYXQgU3lzdGVtLkRpcmVjdG9yeVNlcnZpY2VzLkRpcmVjdG9yeVNlYXJjaGVyLkZp




As you can see the entire information you need (encoding, filename) is available.

Happy parsing!

(God i'm rusty :()

Offline

#5 March 3 2009

mir
Member

Re: Receive Mail with attachement

that is exactly what i ended up doing yesterday.

I will post a more detailed description after i finish the current task
thanks for the help xtrem

Offline

#6 March 4 2009

mir
Member

Re: Receive Mail with attachement

well i got back to this part of the code

it seems working , i have to test with big attachements, and do lot of cleaning in the code and add parameters and check some exceptions

i can send it once i am done if you want.

and i will be looking into other solutions also, then i can move on to the ftp upload and download from secure folder
so if any idea on the second topic already, i would appreciate

Last edited by mir (March 4 2009)

Offline

#7 March 4 2009

rolf
Member

Re: Receive Mail with attachement

in php u can find classes to do that :/ I did it once.
Dont get stuck on c#, try vb and stuff...
im sure someone has the same needs as you, there must me some classes out there...

Alternatively, you can automate outlook using COM.

Last edited by rolf (March 4 2009)

Offline

#8 March 4 2009

mir
Member

Re: Receive Mail with attachement

you can try to get a command line mail client (i think there is a windows port of fetchmail) and control it from the application.

that is what i want, it would be great someone can post a command line mail client that can Receive emails and Download attachment

Last edited by mir (March 4 2009)

Offline

#9 March 4 2009

rolf
Member

Re: Receive Mail with attachement

mir wrote:

you can try to get a command line mail client (i think there is a windows port of fetchmail) and control it from the application.

that is what i want, it would be great someone can post a command line mail client that can Receive emails and Download attachment

Yep i edited my post, i dont think there is such a free client... but still looking.
Sorry if i mislead you.

Offline

#10 March 4 2009

mir
Member

Re: Receive Mail with attachement

no it is not a misleading idea :) thanks for the suggestion

data is confidential, call me she7adeh w msharta, but i can't be using any closed source stuff

i found a tool that do that for free and even gives you lot of GB of free storage to avoid worrying about free space. hassayton awedem aktar min l lzoum

Offline

#11 March 4 2009

rolf
Member

Re: Receive Mail with attachement

BTW, the protocol for receiving email is called POP or POP3.

Offline

#12 March 5 2009

xterm
Moderator

Re: Receive Mail with attachement

mir wrote:

that is what i want, it would be great someone can post a command line mail client that can Receive emails and Download attachment

Honestly i do not like this approach, the least dependencies you have for your application the better. If your task is minor, do it manually and have some control over it. Do you really want to do a system call, pass parameters, parse the output of the call and notify your application?

I bet what you've already done is far better and given a small review of your code with a few optimization, you can run a stress test and make sure its working properly.

Offline

#13 March 5 2009

mir
Member

Re: Receive Mail with attachement

the least dependencies you have for your application the better

we think along the same lines
I will upload the code soon.

some files are 60 MB, i won't be sending that via email, ano akid it will fail on the send and on the receive
I will try to combine the best approach between mail and ftp and will try to divide the files

btw in vb, it is guetting easier to send, download, upload stuff


 If My.Computer.Network.Ping("www.migh.com", 1000) Then
            MsgBox("Server pinged successfully.")
        Else
            MsgBox("Ping request timed out.")
        End If

        My.Computer.Network.DownloadFile _
            ("http://www.migh.info/lbg/file01.txt", _
            "C:\downloads\file01.txt", "usernam", "Password")

i don't think it can get any easier  even with password protected folders

Last edited by mir (March 5 2009)

Offline

Board footer